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 <peff@peff.net>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Thomas Gummerer 2017-03-21 22:12:19 +00:00 committed by Junio C Hamano
parent 869fb8f729
commit e0e7f99ea4
2 changed files with 17 additions and 1 deletions

View File

@ -314,7 +314,9 @@ push_stash () {
if test "$keep_index" = "t" && test -n "$i_tree" if test "$keep_index" = "t" && test -n "$i_tree"
then then
git read-tree --reset -u $i_tree git read-tree --reset $i_tree
git ls-files -z --modified -- "$@" |
git checkout-index -z --force --stdin
fi fi
else else
git apply -R < "$TMP-patch" || git apply -R < "$TMP-patch" ||

View File

@ -907,4 +907,18 @@ test_expect_success 'stash without verb with pathspec' '
test_path_is_file bar test_path_is_file bar
' '
test_expect_success 'stash -k -- <pathspec> leaves unstaged files intact' '
git reset &&
>foo &&
>bar &&
git add foo bar &&
git commit -m "test" &&
echo "foo" >foo &&
echo "bar" >bar &&
git stash -k -- foo &&
test "",bar = $(cat foo),$(cat bar) &&
git stash pop &&
test foo,bar = $(cat foo),$(cat bar)
'
test_done test_done