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

[PATCH 2/2] stash: fix git stash branch regression when branch creation fails

From
Jon Seymour <jon.seymour@gmail.com>
Date
Sep 28, 2010, 13:19 UTC
Message-ID
<1285679992-7638-3-git-send-email-jon.seymour@gmail.com>
In-Reply-To
<1285673120-43354-1-git-send-email-tom@dbservice.com>

Tomas Carnecky reported a regression in the behaviour of git stash branch, when the branch creation fails.

This patch fixes that regression by restoring the pre-condition for dropping that previously existed.

This patch assumes Tomas Carnecky's patch has already been applied.
Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 git-stash.sh     |    6 +++---
 t/t3903-stash.sh |    2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/git-stash.sh b/git-stash.sh
index 23a9ab5..5fb1245 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -432,9 +432,9 @@ apply_to_branch () {
 	assert_stash_like "$@"
 
 	git checkout -b $branch $REV^ &&
-	apply_stash "$@"
-
-	test -z "$IS_STASH_REF" || drop_stash "$@"
+	apply_stash "$@" && {
+		test -z "$IS_STASH_REF" || drop_stash "$@"
+	}
 }
 
 PARSE_CACHE='--not-parsed'
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 0f6b2e4..336e244 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -545,7 +545,7 @@ test_expect_success 'invalid ref of the form stash@{n}, n >= N' '
 	git stash drop
 '
 
-test_expect_failure 'stash branch should not drop the stash if the branch exists' '
+test_expect_success 'stash branch should not drop the stash if the branch exists' '
 	git stash clear &&
 	echo foo > file &&
 	git add file &&
-- 
1.7.3.4.g787b.dirty
Previous: Jon Seymour
Message 6 of 6 in “stash drops the stash even if creating the branch fails because it already exists”
  1. stash drops the stash even if creating the branch fails because it already existsTomas Carnecky, Sep 28, 2010
  2. 0/2 stash: test and fix git stash branch regressionJon Seymour, Sep 28, 2010
  3. 1/2 stash drops the stash even if creating the branch fails because it already existsJon Seymour, Sep 28, 2010
  4. Tomas CarneckySep 28, 2010
  5. Jon SeymourSep 29, 2010
  6. 2/2 stash: fix git stash branch regression when branch creation failsJon Seymour, Sep 28, 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.