From c95bc226d4ccc313303f700f11815c03fbec4efc Mon Sep 17 00:00:00 2001 From: Joel Teichroeb Date: Sat, 19 Aug 2017 13:13:24 -0700 Subject: [PATCH 1/3] stash: add a test for stash create with no files Ensure the command suceeds and outputs nothing Signed-off-by: Joel Teichroeb Signed-off-by: Junio C Hamano --- t/t3903-stash.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 4046817d70..f0708ced27 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -444,6 +444,14 @@ test_expect_failure 'stash file to directory' ' test foo = "$(cat file/file)" ' +test_expect_success 'stash create - no changes' ' + git stash clear && + test_when_finished "git reset --hard HEAD" && + git reset --hard && + git stash create >actual && + test_must_be_empty actual +' + test_expect_success 'stash branch - no stashes on stack, stash-like argument' ' git stash clear && test_when_finished "git reset --hard HEAD" && From b04e6915fa047bb3103e5be83953f2ca0b4b115b Mon Sep 17 00:00:00 2001 From: Joel Teichroeb Date: Sat, 19 Aug 2017 13:13:25 -0700 Subject: [PATCH 2/3] stash: add a test for when apply fails during stash branch If the return value of merge recursive is not checked, the stash could end up being dropped even though it was not applied properly Signed-off-by: Joel Teichroeb Signed-off-by: Junio C Hamano --- t/t3903-stash.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index f0708ced27..887010c497 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -656,6 +656,20 @@ test_expect_success 'stash branch should not drop the stash if the branch exists git rev-parse stash@{0} -- ' +test_expect_success 'stash branch should not drop the stash if the apply fails' ' + git stash clear && + git reset HEAD~1 --hard && + echo foo >file && + git add file && + git commit -m initial && + echo bar >file && + git stash && + echo baz >file && + test_when_finished "git checkout master" && + test_must_fail git stash branch new_branch stash@{0} && + git rev-parse stash@{0} -- +' + test_expect_success 'stash apply shows status same as git status (relative to current directory)' ' git stash clear && echo 1 >subdir/subfile1 && From 4e9bf3dd6daec09b9a0b110825093c6a480f92e4 Mon Sep 17 00:00:00 2001 From: Joel Teichroeb Date: Sat, 19 Aug 2017 13:13:26 -0700 Subject: [PATCH 3/3] stash: add a test for stashing in a detached state All that we are really testing here is that the message is correct when we are not on any branch. All other functionality is already tested elsewhere. Signed-off-by: Joel Teichroeb Signed-off-by: Junio C Hamano --- t/t3903-stash.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 887010c497..3b1ac1971a 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -822,6 +822,18 @@ test_expect_success 'create with multiple arguments for the message' ' test_cmp expect actual ' +test_expect_success 'create in a detached state' ' + test_when_finished "git checkout master" && + git checkout HEAD~1 && + >foo && + git add foo && + STASH_ID=$(git stash create) && + HEAD_ID=$(git rev-parse --short HEAD) && + echo "WIP on (no branch): ${HEAD_ID} initial" >expect && + git show --pretty=%s -s ${STASH_ID} >actual && + test_cmp expect actual +' + test_expect_success 'stash -- stashes and restores the file' ' >foo && >bar &&