From: Jon Seymour Date: Sun, 08 Aug 2010 04:46:08 GMT Subject: [PATCH v3 6/9] stash: teach git stash branch to tolerate stash-like arguments Message-ID: <1281242771-24764-7-git-send-email-jon.seymour@gmail.com> In-Reply-To: <1281242771-24764-1-git-send-email-jon.seymour@gmail.com> 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. Signed-off-by: Jon Seymour --- git-stash.sh | 15 +++++++++++---- 1 files changed, 11 insertions(+), 4 deletions(-) diff --git a/git-stash.sh b/git-stash.sh index 86cd446..97e3749 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -390,20 +390,27 @@ drop_stash () { } apply_to_branch () { - have_stash || die 'Nothing to apply' - test -n "$1" || die 'No branch name specified' branch=$1 if test -z "$2" then set x "$ref_stash@{0}" + have_stash || die 'Nothing to apply' fi stash=$2 + assert_stash_like "$stash" + git checkout -b $branch $stash^ && - apply_stash --index $stash && - drop_stash $stash + apply_stash --index $stash + + if is_stash_ref "$stash" + then + drop_stash "$stash" + else + true + fi } # The default command is "save" if nothing but options are given -- 1.7.2.1.51.g82c0c0