stash: Don't fail if work dir contains file named 'HEAD'
When performing a plain "git stash" (without --patch), git-diff would fail with "fatal: ambiguous argument 'HEAD': both revision and filename". The output was piped into git-update-index, masking the failed exit status. The output is now sent to a temporary file (which is cleaned up by existing code), and the exit status is checked. The "HEAD" arg to the git-diff invocation has been disambiguated too, of course. In patch mode, "git stash -p" would fail harmlessly, leaving the working dir untouched. Interactive adding is fine, but the resulting tree was diffed with an ambiguous 'HEAD' argument. Use >foo (no space) when redirecting output. In t3904, checks and operations on each file are in the order they'll appear when interactively staging. In t3905, fix a bug in "stash save --include-untracked -q is quiet": The redirected stdout file was considered untracked, and so was removed from the working directory. Use test path helper functions where appropriate. Signed-off-by: Jonathon Mah <me@JonathonMah.com> Acked-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
17b4e93d5b
commit
44df2e2970
@ -115,7 +115,8 @@ create_stash () {
|
||||
git read-tree --index-output="$TMPindex" -m $i_tree &&
|
||||
GIT_INDEX_FILE="$TMPindex" &&
|
||||
export GIT_INDEX_FILE &&
|
||||
git diff --name-only -z HEAD | git update-index -z --add --remove --stdin &&
|
||||
git diff --name-only -z HEAD -- >"$TMP-stagenames" &&
|
||||
git update-index -z --add --remove --stdin <"$TMP-stagenames" &&
|
||||
git write-tree &&
|
||||
rm -f "$TMPindex"
|
||||
) ) ||
|
||||
@ -134,7 +135,7 @@ create_stash () {
|
||||
w_tree=$(GIT_INDEX_FILE="$TMP-index" git write-tree) ||
|
||||
die "$(gettext "Cannot save the current worktree state")"
|
||||
|
||||
git diff-tree -p HEAD $w_tree > "$TMP-patch" &&
|
||||
git diff-tree -p HEAD $w_tree -- >"$TMP-patch" &&
|
||||
test -s "$TMP-patch" ||
|
||||
die "$(gettext "No changes selected")"
|
||||
|
||||
@ -491,7 +492,7 @@ drop_stash () {
|
||||
die "$(eval_gettext "\${REV}: Could not drop stash entry")"
|
||||
|
||||
# clear_stash if we just dropped the last stash entry
|
||||
git rev-parse --verify "$ref_stash@{0}" > /dev/null 2>&1 || clear_stash
|
||||
git rev-parse --verify "$ref_stash@{0}" >/dev/null 2>&1 || clear_stash
|
||||
}
|
||||
|
||||
apply_to_branch () {
|
||||
|
Reference in New Issue
Block a user