Skip to content

Commit f6a47f9

Browse files
committed
Merge branch 'jt/stash-tests'
Test update to improve coverage for "git stash" operations. * jt/stash-tests: stash: add a test for stashing in a detached state stash: add a test for when apply fails during stash branch stash: add a test for stash create with no files
2 parents 06cf4f2 + 4e9bf3d commit f6a47f9

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

t/t3903-stash.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,14 @@ test_expect_failure 'stash file to directory' '
444444
test foo = "$(cat file/file)"
445445
'
446446

447+
test_expect_success 'stash create - no changes' '
448+
git stash clear &&
449+
test_when_finished "git reset --hard HEAD" &&
450+
git reset --hard &&
451+
git stash create >actual &&
452+
test_must_be_empty actual
453+
'
454+
447455
test_expect_success 'stash branch - no stashes on stack, stash-like argument' '
448456
git stash clear &&
449457
test_when_finished "git reset --hard HEAD" &&
@@ -648,6 +656,20 @@ test_expect_success 'stash branch should not drop the stash if the branch exists
648656
git rev-parse stash@{0} --
649657
'
650658

659+
test_expect_success 'stash branch should not drop the stash if the apply fails' '
660+
git stash clear &&
661+
git reset HEAD~1 --hard &&
662+
echo foo >file &&
663+
git add file &&
664+
git commit -m initial &&
665+
echo bar >file &&
666+
git stash &&
667+
echo baz >file &&
668+
test_when_finished "git checkout master" &&
669+
test_must_fail git stash branch new_branch stash@{0} &&
670+
git rev-parse stash@{0} --
671+
'
672+
651673
test_expect_success 'stash apply shows status same as git status (relative to current directory)' '
652674
git stash clear &&
653675
echo 1 >subdir/subfile1 &&
@@ -800,6 +822,18 @@ test_expect_success 'create with multiple arguments for the message' '
800822
test_cmp expect actual
801823
'
802824

825+
test_expect_success 'create in a detached state' '
826+
test_when_finished "git checkout master" &&
827+
git checkout HEAD~1 &&
828+
>foo &&
829+
git add foo &&
830+
STASH_ID=$(git stash create) &&
831+
HEAD_ID=$(git rev-parse --short HEAD) &&
832+
echo "WIP on (no branch): ${HEAD_ID} initial" >expect &&
833+
git show --pretty=%s -s ${STASH_ID} >actual &&
834+
test_cmp expect actual
835+
'
836+
803837
test_expect_success 'stash -- <pathspec> stashes and restores the file' '
804838
>foo &&
805839
>bar &&

0 commit comments

Comments
 (0)