Skip to content

Commit e0e7f99

Browse files
tgummerergitster
authored andcommitted
stash: keep untracked files intact in stash -k
Currently when there are untracked changes in a file "one" and in a file "two" in the repository and the user uses: git stash push -k one all changes in "two" are wiped out completely. That is clearly not the intended result. Make sure that only the files given in the pathspec are changed when git stash push -k <pathspec> is used. Reported-by: Jeff King <[email protected]> Signed-off-by: Thomas Gummerer <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 869fb8f commit e0e7f99

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

git-stash.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ push_stash () {
314314

315315
if test "$keep_index" = "t" && test -n "$i_tree"
316316
then
317-
git read-tree --reset -u $i_tree
317+
git read-tree --reset $i_tree
318+
git ls-files -z --modified -- "$@" |
319+
git checkout-index -z --force --stdin
318320
fi
319321
else
320322
git apply -R < "$TMP-patch" ||

t/t3903-stash.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,4 +907,18 @@ test_expect_success 'stash without verb with pathspec' '
907907
test_path_is_file bar
908908
'
909909

910+
test_expect_success 'stash -k -- <pathspec> leaves unstaged files intact' '
911+
git reset &&
912+
>foo &&
913+
>bar &&
914+
git add foo bar &&
915+
git commit -m "test" &&
916+
echo "foo" >foo &&
917+
echo "bar" >bar &&
918+
git stash -k -- foo &&
919+
test "",bar = $(cat foo),$(cat bar) &&
920+
git stash pop &&
921+
test foo,bar = $(cat foo),$(cat bar)
922+
'
923+
910924
test_done

0 commit comments

Comments
 (0)