git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jon Seymour <jon.seymour@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, ams@toroid.org, jon.seymour@gmail.com
Subject: [PATCH v2 2/3] stash: Allow git stash branch to process commits that look like stashes but are not stash references.
Date: Tue,  3 Aug 2010 20:36:14 +1000	[thread overview]
Message-ID: <1280831775-30759-3-git-send-email-jon.seymour@gmail.com> (raw)
In-Reply-To: <1280831775-30759-1-git-send-email-jon.seymour@gmail.com>

This patch allows git stash branch to work with stash-like commits created by git stash create.

Two changes were required:

* relax the pre-condition so that a stash stack is required if and only if a stash argument is not specified
* don't attempt to drop a stash argument that doesn't look like a stash reference.


Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 git-stash.sh |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/git-stash.sh b/git-stash.sh
index 1d95447..432ddae 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -225,6 +225,12 @@ show_stash () {
 	git diff $flags $b_commit $w_commit
 }
 
+if_stash_ref() {
+	ref="$1"
+	shift
+	test "${ref#stash}" = "${ref}" -a "${ref#$ref_stash}" = "${ref}" || "$@"
+}
+
 apply_stash () {
 	applied_stash=
 	unstash_index=
@@ -359,20 +365,20 @@ 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
+		have_stash || die 'Nothing to apply'
 		set x "$ref_stash@{0}"
 	fi
 	stash=$2
 
 	git checkout -b $branch $stash^ &&
 	apply_stash --index $stash &&
-	drop_stash $stash
+	if_stash_ref "$stash" drop_stash "$stash"
 }
 
 # The default command is "save" if nothing but options are given
-- 
1.7.2.1.111.g8fc90

  parent reply	other threads:[~2010-08-03 10:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-03 10:36 [PATCH v2 0/3] *** SUBJECT HERE *** Jon Seymour
2010-08-03 10:36 ` [PATCH v2 1/3] stash: It looks like a stash, but doesn't quack like a stash Jon Seymour
2010-08-04 23:31   ` Junio C Hamano
2010-08-03 10:36 ` Jon Seymour [this message]
2010-08-04 23:51   ` [PATCH v2 2/3] stash: Allow git stash branch to process commits that look like stashes but are not stash references Junio C Hamano
2010-08-05  5:23     ` Jon Seymour
2010-08-05  7:50       ` Jon Seymour
2010-08-05 20:13         ` Junio C Hamano
2010-08-03 10:36 ` [PATCH v2 3/3] stash: modify tests to reflect stash branch fixes Jon Seymour

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1280831775-30759-3-git-send-email-jon.seymour@gmail.com \
    --to=jon.seymour@gmail.com \
    --cc=ams@toroid.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).