File tree Expand file tree Collapse file tree 3 files changed +25
-4
lines changed Expand file tree Collapse file tree 3 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -136,11 +136,12 @@ save_stash () {
136
136
keep_index=t
137
137
;;
138
138
--no-keep-index)
139
- keep_index=
139
+ keep_index=n
140
140
;;
141
141
-p|--patch)
142
142
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
144
145
;;
145
146
-q|--quiet)
146
147
GIT_QUIET=t
@@ -185,15 +186,15 @@ save_stash () {
185
186
then
186
187
git reset --hard ${GIT_QUIET: +-q}
187
188
188
- if test -n " $keep_index " && test -n $i_tree
189
+ if test " $keep_index " = " t " && test -n $i_tree
189
190
then
190
191
git read-tree --reset -u $i_tree
191
192
fi
192
193
else
193
194
git apply -R < " $TMP -patch" ||
194
195
die " Cannot remove worktree changes"
195
196
196
- if test -z " $keep_index "
197
+ if test " $keep_index " ! = " t "
197
198
then
198
199
git reset
199
200
fi
Original file line number Diff line number Diff line change @@ -230,6 +230,14 @@ test_expect_success 'stash -k' '
230
230
test bar,bar4 = $(cat file),$(cat file2)
231
231
'
232
232
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
+
233
241
test_expect_success ' stash --invalid-option' '
234
242
echo bar5 > file &&
235
243
echo bar6 > file2 &&
Original file line number Diff line number Diff line change @@ -48,6 +48,18 @@ test_expect_success PERL 'git stash -p --no-keep-index' '
48
48
verify_state bar dummy bar_index
49
49
'
50
50
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
+
51
63
test_expect_success PERL ' none of this moved HEAD' '
52
64
verify_saved_head
53
65
'
You can’t perform that action at this time.
0 commit comments