From 44df2e297025d7a9af6c265dfefb687b09e2537a Mon Sep 17 00:00:00 2001 From: Jonathon Mah Date: Fri, 30 Dec 2011 16:14:01 -0800 Subject: 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 Acked-by: Thomas Rast Signed-off-by: Junio C Hamano --- t/t3904-stash-patch.sh | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 't/t3904-stash-patch.sh') diff --git a/t/t3904-stash-patch.sh b/t/t3904-stash-patch.sh index 781fd71681..70655c1848 100755 --- a/t/t3904-stash-patch.sh +++ b/t/t3904-stash-patch.sh @@ -7,7 +7,8 @@ test_expect_success PERL 'setup' ' mkdir dir && echo parent > dir/foo && echo dummy > bar && - git add bar dir/foo && + echo committed > HEAD && + git add bar dir/foo HEAD && git commit -m initial && test_tick && test_commit second dir/foo head && @@ -17,47 +18,57 @@ test_expect_success PERL 'setup' ' save_head ' -# note: bar sorts before dir, so the first 'n' is always to skip 'bar' +# note: order of files with unstaged changes: HEAD bar dir/foo test_expect_success PERL 'saying "n" does nothing' ' + set_state HEAD HEADfile_work HEADfile_index && set_state dir/foo work index && - (echo n; echo n) | test_must_fail git stash save -p && - verify_state dir/foo work index && - verify_saved_state bar + (echo n; echo n; echo n) | test_must_fail git stash save -p && + verify_state HEAD HEADfile_work HEADfile_index && + verify_saved_state bar && + verify_state dir/foo work index ' test_expect_success PERL 'git stash -p' ' - (echo n; echo y) | git stash save -p && - verify_state dir/foo head index && + (echo y; echo n; echo y) | git stash save -p && + verify_state HEAD committed HEADfile_index && verify_saved_state bar && + verify_state dir/foo head index && git reset --hard && git stash apply && - verify_state dir/foo work head && - verify_state bar dummy dummy + verify_state HEAD HEADfile_work committed && + verify_state bar dummy dummy && + verify_state dir/foo work head ' test_expect_success PERL 'git stash -p --no-keep-index' ' - set_state dir/foo work index && + set_state HEAD HEADfile_work HEADfile_index && set_state bar bar_work bar_index && - (echo n; echo y) | git stash save -p --no-keep-index && - verify_state dir/foo head head && + set_state dir/foo work index && + (echo y; echo n; echo y) | git stash save -p --no-keep-index && + verify_state HEAD committed committed && verify_state bar bar_work dummy && + verify_state dir/foo head head && git reset --hard && git stash apply --index && - verify_state dir/foo work index && - verify_state bar dummy bar_index + verify_state HEAD HEADfile_work HEADfile_index && + verify_state bar dummy bar_index && + verify_state dir/foo work index ' test_expect_success PERL 'git stash --no-keep-index -p' ' - set_state dir/foo work index && + set_state HEAD HEADfile_work HEADfile_index && set_state bar bar_work bar_index && - (echo n; echo y) | git stash save --no-keep-index -p && + set_state dir/foo work index && + (echo y; echo n; echo y) | git stash save --no-keep-index -p && + verify_state HEAD committed committed && verify_state dir/foo head head && verify_state bar bar_work dummy && git reset --hard && git stash apply --index && - verify_state dir/foo work index && - verify_state bar dummy bar_index + verify_state HEAD HEADfile_work HEADfile_index && + verify_state bar dummy bar_index && + verify_state dir/foo work index ' test_expect_success PERL 'none of this moved HEAD' ' -- cgit v1.2.3