Skip to content

Commit 460ccd0

Browse files
trastgitster
authored andcommitted
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 <[email protected]> Acked-by: Stephen Boyd <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8324b97 commit 460ccd0

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

git-stash.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ show_stash () {
222222
}
223223

224224
apply_stash () {
225+
applied_stash=
225226
unstash_index=
226227

227228
while test $# != 0
@@ -243,6 +244,9 @@ apply_stash () {
243244
if test $# = 0
244245
then
245246
have_stash || die 'Nothing to apply'
247+
applied_stash="$ref_stash@{0}"
248+
else
249+
applied_stash="$*"
246250
fi
247251

248252
# stash records the work tree, and is a merge between the
@@ -421,8 +425,7 @@ pop)
421425
shift
422426
if apply_stash "$@"
423427
then
424-
test -z "$unstash_index" || shift
425-
drop_stash "$@"
428+
drop_stash "$applied_stash"
426429
fi
427430
;;
428431
branch)

t/t3903-stash.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ test_expect_success 'pop -q is quiet' '
194194
test ! -s output.out
195195
'
196196

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+
197206
test_expect_success 'drop -q is quiet' '
198207
git stash &&
199208
git stash drop -q > output.out 2>&1 &&

0 commit comments

Comments
 (0)