detached-stash: simplify git stash branch
This patch teaches git stash branch to tolerate stash-like arguments. In particular, a stash is only required if an argument isn't specified and the stash is only dropped if a stash entry reference was specified or implied. The implementation has been simplified by taking advantage of assert_stash_like() and the variables established by parse_flags_and_rev(). Signed-off-by: Jon Seymour <jon.seymour@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jon Seymour committed
Aug 21, 2010 at 14:09 UTC
fb433dc912ffb64364571750bedde988f29e736b
1 file changed
+7
-10
git-stash.sh
+7
-10
@@ -441,20 +441,17 @@ drop_stash () {
441
}
442
443
apply_to_branch () {
444
- have_stash || die 'Nothing to apply'
445
-
444
test -n "$1" || die 'No branch name specified'
445
branch=$1
446
+ shift 1
447
449
- if test -z "$2"
450
- then
451
- set x "$ref_stash@{0}"
452
- fi
453
- stash=$2
448
+ set -- --index "$@"
449
+ assert_stash_like "$@"
450
+
451
+ git checkout -b $branch $REV^ &&
452
+ apply_stash "$@"
453
455
- git checkout -b $branch $stash^ &&
456
- apply_stash --index $stash &&
457
- drop_stash $stash
454
+ test -z "$IS_STASH_REF" || drop_stash "$@"
455
}
456
457
PARSE_CACHE='--not-parsed'