git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/3] stash: Allow git stash branch to process commits that look like stashes but are not stash references.

From
Jon Seymour <jon.seymour@gmail.com>
Date
Aug 3, 2010, 10:36 UTC
Message-ID
<1280831775-30759-3-git-send-email-jon.seymour@gmail.com>
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
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 9 in “*** SUBJECT HERE ***”
  1. 0/3 *** SUBJECT HERE ***Jon Seymour, Aug 3, 2010
  2. 1/3 stash: It looks like a stash, but doesn't quack like a stash...Jon Seymour, Aug 3, 2010
  3. Junio C HamanoAug 4, 2010
  4. 2/3 stash: Allow git stash branch to process commits that look like stashes but are not stash references.Jon Seymour, Aug 3, 2010
  5. Junio C HamanoAug 4, 2010
  6. Jon SeymourAug 5, 2010
  7. Jon SeymourAug 5, 2010
  8. Junio C HamanoAug 5, 2010
  9. 3/3 stash: modify tests to reflect stash branch fixes.Jon Seymour, Aug 3, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.