Skip to content

Commit 869fb8f

Browse files
tgummerergitster
authored andcommitted
stash: pass the pathspec argument to git reset
For "git stash -p --no-keep-index", the pathspec argument is currently not passed to "git reset". This means that changes that are staged but that are excluded from the pathspec still get unstaged by git stash -p. Make sure that doesn't happen by passing the pathspec argument to the git reset in question, bringing the behaviour in line with "git stash -- <pathspec>". Signed-off-by: Thomas Gummerer <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1790f4f commit 869fb8f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

git-stash.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ push_stash () {
322322

323323
if test "$keep_index" != "t"
324324
then
325-
git reset -q
325+
git reset -q -- "$@"
326326
fi
327327
fi
328328
}

t/t3904-stash-patch.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ test_expect_success 'git stash --no-keep-index -p' '
7777
verify_state dir/foo work index
7878
'
7979

80+
test_expect_success 'stash -p --no-keep-index -- <pathspec> does not unstage other files' '
81+
set_state HEAD HEADfile_work HEADfile_index &&
82+
set_state dir/foo work index &&
83+
echo y | git stash push -p --no-keep-index -- HEAD &&
84+
verify_state HEAD committed committed &&
85+
verify_state dir/foo work index
86+
'
87+
8088
test_expect_success 'none of this moved HEAD' '
8189
verify_saved_head
8290
'

0 commit comments

Comments
 (0)