Skip to content

Commit e9f1878

Browse files
committed
Merge branch 'dm/stash-k-i-p' into maint
* dm/stash-k-i-p: stash: ensure --no-keep-index and --patch can be used in any order stash: add two more tests for --no-keep-index
2 parents f28d2e3 + 3a243f7 commit e9f1878

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
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/t3903-stash.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ test_expect_success 'stash -k' '
230230
test bar,bar4 = $(cat file),$(cat file2)
231231
'
232232

233+
test_expect_success 'stash --no-keep-index' '
234+
echo bar33 > file &&
235+
echo bar44 > file2 &&
236+
git add file2 &&
237+
git stash --no-keep-index &&
238+
test bar,bar2 = $(cat file),$(cat file2)
239+
'
240+
233241
test_expect_success 'stash --invalid-option' '
234242
echo bar5 > file &&
235243
echo bar6 > file2 &&

t/t3904-stash-patch.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ test_expect_success PERL 'git stash -p --no-keep-index' '
4848
verify_state bar dummy bar_index
4949
'
5050

51+
test_expect_success PERL 'git stash --no-keep-index -p' '
52+
set_state dir/foo work index &&
53+
set_state bar bar_work bar_index &&
54+
(echo n; echo y) | git stash save --no-keep-index -p &&
55+
verify_state dir/foo head head &&
56+
verify_state bar bar_work dummy &&
57+
git reset --hard &&
58+
git stash apply --index &&
59+
verify_state dir/foo work index &&
60+
verify_state bar dummy bar_index
61+
'
62+
5163
test_expect_success PERL 'none of this moved HEAD' '
5264
verify_saved_head
5365
'

0 commit comments

Comments
 (0)