Skip to content

Commit fb433dc

Browse files
jonseymourgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f276872 commit fb433dc

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

git-stash.sh

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -441,20 +441,17 @@ drop_stash () {
441441
}
442442

443443
apply_to_branch () {
444-
have_stash || die 'Nothing to apply'
445-
446444
test -n "$1" || die 'No branch name specified'
447445
branch=$1
446+
shift 1
448447

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 "$@"
454453

455-
git checkout -b $branch $stash^ &&
456-
apply_stash --index $stash &&
457-
drop_stash $stash
454+
test -z "$IS_STASH_REF" || drop_stash "$@"
458455
}
459456

460457
PARSE_CACHE='--not-parsed'

0 commit comments

Comments
 (0)