@matheusbsbs / matheus-bagliano / commits / 460ccd0e19
Fork 0

stash pop: remove 'apply' options during 'drop' invocation

The 'git stash pop' option parsing used to remove the first argument in --index mode. At the time this was implemented, this first argument was always --index. However, since the invention of the -q option in fcdd0e9 (stash: teach quiet option, 2009-06-17) you can cause an internal invocation of git stash drop --index by running git stash pop -q --index which then of course fails because drop doesn't know --index. To handle this, instead let 'git stash apply' decide what the future argument to 'drop' should be. Warning: this means that 'git stash apply' must parse all options that 'drop' can take, and deal with them in the same way. This is currently true for its only option -q. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Acked-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Feb 15, 2010 at 17:05 UTC 460ccd0e19774fd5e4f69de5a454068c686ac5a6
2 files changed +14 -2
git-stash.sh
+5 -2
@@ -222,6 +222,7 @@ show_stash () {
222 }
223
224 apply_stash () {
225 + applied_stash=
226 unstash_index=
227
228 while test $# != 0
@@ -243,6 +244,9 @@ apply_stash () {
244 if test $# = 0
245 then
246 have_stash || die 'Nothing to apply'
247 + applied_stash="$ref_stash@{0}"
248 + else
249 + applied_stash="$*"
250 fi
251
252 # stash records the work tree, and is a merge between the
@@ -421,8 +425,7 @@ pop)
425 shift
426 if apply_stash "$@"
427 then
424 - test -z "$unstash_index" || shift
425 - drop_stash "$@"
428 + drop_stash "$applied_stash"
429 fi
430 ;;
431 branch)
t/t3903-stash.sh
+9
@@ -194,6 +194,15 @@ test_expect_success 'pop -q is quiet' '
194 test ! -s output.out
195 '
196
197 +test_expect_success 'pop -q --index works and is quiet' '
198 + echo foo > file &&
199 + git add file &&
200 + git stash save --quiet &&
201 + git stash pop -q --index > output.out 2>&1 &&
202 + test foo = "$(git show :file)" &&
203 + test ! -s output.out
204 +'
205 +
206 test_expect_success 'drop -q is quiet' '
207 git stash &&
208 git stash drop -q > output.out 2>&1 &&