Skip to content

Commit 984c833

Browse files
committed
Merge branch 'tg/stash-with-pathspec-fix' into maint
"git stash -- <pathspec>" incorrectly blew away untracked files in the directory that matched the pathspec, which has been corrected. * tg/stash-with-pathspec-fix: stash: don't delete untracked files that match pathspec
2 parents 1363914 + bba067d commit 984c833

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

git-stash.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,9 @@ push_stash () {
322322

323323
if test $# != 0
324324
then
325-
git reset -q -- "$@"
326-
git ls-files -z --modified -- "$@" |
325+
git add -u -- "$@" |
327326
git checkout-index -z --force --stdin
328-
git clean --force -q -d -- "$@"
327+
git diff-index -p --cached --binary HEAD -- "$@" | git apply --index -R
329328
else
330329
git reset --hard -q
331330
fi

t/t3903-stash.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,4 +1064,36 @@ test_expect_success 'stash -k -- <pathspec> leaves unstaged files intact' '
10641064
test foo,bar = $(cat foo),$(cat bar)
10651065
'
10661066

1067+
test_expect_success 'stash -- <subdir> leaves untracked files in subdir intact' '
1068+
git reset &&
1069+
>subdir/untracked &&
1070+
>subdir/tracked1 &&
1071+
>subdir/tracked2 &&
1072+
git add subdir/tracked* &&
1073+
git stash -- subdir/ &&
1074+
test_path_is_missing subdir/tracked1 &&
1075+
test_path_is_missing subdir/tracked2 &&
1076+
test_path_is_file subdir/untracked &&
1077+
git stash pop &&
1078+
test_path_is_file subdir/tracked1 &&
1079+
test_path_is_file subdir/tracked2 &&
1080+
test_path_is_file subdir/untracked
1081+
'
1082+
1083+
test_expect_success 'stash -- <subdir> works with binary files' '
1084+
git reset &&
1085+
>subdir/untracked &&
1086+
>subdir/tracked &&
1087+
cp "$TEST_DIRECTORY"/test-binary-1.png subdir/tracked-binary &&
1088+
git add subdir/tracked* &&
1089+
git stash -- subdir/ &&
1090+
test_path_is_missing subdir/tracked &&
1091+
test_path_is_missing subdir/tracked-binary &&
1092+
test_path_is_file subdir/untracked &&
1093+
git stash pop &&
1094+
test_path_is_file subdir/tracked &&
1095+
test_path_is_file subdir/tracked-binary &&
1096+
test_path_is_file subdir/untracked
1097+
'
1098+
10671099
test_done

0 commit comments

Comments
 (0)