diff options
author | Aaron M Watson <watsona4@gmail.com> | 2016-10-25 01:40:13 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-10-26 18:58:10 +0200 |
commit | a56c8f5aab5a6ffdd687de5134883df60cc4c919 (patch) | |
tree | 7a068256143229f9287f7fda9fded15b8d57bc50 /t/t3903-stash.sh | |
parent | Sync with maint (diff) | |
download | git-a56c8f5aab5a6ffdd687de5134883df60cc4c919.tar.xz git-a56c8f5aab5a6ffdd687de5134883df60cc4c919.zip |
stash: allow stashes to be referenced by index only
Instead of referencing "stash@{n}" explicitly, make it possible to
simply reference as "n". Most users only reference stashes by their
position in the stash stack (what I refer to as the "index" here).
The syntax for the typical stash (stash@{n}) is slightly annoying and
easy to forget, and sometimes difficult to escape properly in a
script. Because of this the capability to do things with the stash by
simply referencing the index is desirable.
This patch includes the superior implementation provided by Ă˜sse Walle
(thanks for that), with a slight change to fix a broken test in the test
suite. I also merged the test scripts as suggested by Jeff King, and
un-wrapped the documentation as suggested by Junio Hamano.
Signed-off-by: Aaron M Watson <watsona4@gmail.com>
Reviewed-by: Jeff King <peff@peff.net>
Diffstat (limited to 't/t3903-stash.sh')
-rwxr-xr-x | t/t3903-stash.sh | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 2142c1fa92..e1a6ccc00c 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -131,6 +131,26 @@ test_expect_success 'drop middle stash' ' test 1 = $(git show HEAD:file) ' +test_expect_success 'drop middle stash by index' ' + git reset --hard && + echo 8 >file && + git stash && + echo 9 >file && + git stash && + git stash drop 1 && + test 2 = $(git stash list | wc -l) && + git stash apply && + test 9 = $(cat file) && + test 1 = $(git show :file) && + test 1 = $(git show HEAD:file) && + git reset --hard && + git stash drop && + git stash apply && + test 3 = $(cat file) && + test 1 = $(git show :file) && + test 1 = $(git show HEAD:file) +' + test_expect_success 'stash pop' ' git reset --hard && git stash pop && @@ -604,6 +624,21 @@ test_expect_success 'invalid ref of the form stash@{n}, n >= N' ' git stash drop ' +test_expect_success 'invalid ref of the form "n", n >= N' ' + git stash clear && + test_must_fail git stash drop 0 && + echo bar5 >file && + echo bar6 >file2 && + git add file2 && + git stash && + test_must_fail git stash drop 1 && + test_must_fail git stash pop 1 && + test_must_fail git stash apply 1 && + test_must_fail git stash show 1 && + test_must_fail git stash branch tmp 1 && + git stash drop +' + test_expect_success 'stash branch should not drop the stash if the branch exists' ' git stash clear && echo foo >file && |