Skip to content

Commit 3a243f7

Browse files
toofishesgitster
authored andcommitted
stash: ensure --no-keep-index and --patch can be used in any order
Don't assume one comes after the other on the command line. Use a three-state variable to track and check its value accordingly. Signed-off-by: Dan McGee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 21ec98a commit 3a243f7

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

git-stash.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,12 @@ save_stash () {
136136
keep_index=t
137137
;;
138138
--no-keep-index)
139-
keep_index=
139+
keep_index=n
140140
;;
141141
-p|--patch)
142142
patch_mode=t
143-
keep_index=t
143+
# only default to keep if we don't already have an override
144+
test -z "$keep_index" && keep_index=t
144145
;;
145146
-q|--quiet)
146147
GIT_QUIET=t
@@ -185,15 +186,15 @@ save_stash () {
185186
then
186187
git reset --hard ${GIT_QUIET:+-q}
187188

188-
if test -n "$keep_index" && test -n $i_tree
189+
if test "$keep_index" = "t" && test -n $i_tree
189190
then
190191
git read-tree --reset -u $i_tree
191192
fi
192193
else
193194
git apply -R < "$TMP-patch" ||
194195
die "Cannot remove worktree changes"
195196

196-
if test -z "$keep_index"
197+
if test "$keep_index" != "t"
197198
then
198199
git reset
199200
fi

t/t3904-stash-patch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ test_expect_success PERL 'git stash -p --no-keep-index' '
4848
verify_state bar dummy bar_index
4949
'
5050

51-
test_expect_failure PERL 'git stash --no-keep-index -p' '
51+
test_expect_success PERL 'git stash --no-keep-index -p' '
5252
set_state dir/foo work index &&
5353
set_state bar bar_work bar_index &&
5454
(echo n; echo y) | git stash save --no-keep-index -p &&

0 commit comments

Comments
 (0)