@matheusbsbs / matheus-bagliano / commits / 3a243f7024
Fork 0

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 <dpmcgee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Dan McGee committed Apr 7, 2011 at 12:04 UTC 3a243f7024f21c2c2205cd861f3bb756b0ec43a0
2 files changed +6 -5
git-stash.sh
+5 -4
@@ -136,11 +136,12 @@ save_stash () {
136 keep_index=t
137 ;;
138 --no-keep-index)
139 - keep_index=
139 + keep_index=n
140 ;;
141 -p|--patch)
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
145 ;;
146 -q|--quiet)
147 GIT_QUIET=t
@@ -185,7 +186,7 @@ save_stash () {
186 then
187 git reset --hard ${GIT_QUIET:+-q}
188
188 - if test -n "$keep_index" && test -n $i_tree
189 + if test "$keep_index" = "t" && test -n $i_tree
190 then
191 git read-tree --reset -u $i_tree
192 fi
@@ -193,7 +194,7 @@ save_stash () {
194 git apply -R < "$TMP-patch" ||
195 die "Cannot remove worktree changes"
196
196 - if test -z "$keep_index"
197 + if test "$keep_index" != "t"
198 then
199 git reset
200 fi
t/t3904-stash-patch.sh
+1 -1
@@ -48,7 +48,7 @@ test_expect_success PERL 'git stash -p --no-keep-index' '
48 verify_state bar dummy bar_index
49 '
50
51 -test_expect_failure PERL 'git stash --no-keep-index -p' '
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 &&