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

[PATCH] contrib/subtree: don't delete remote branches if split fails

From
John Keeping <john@keeping.me.uk>
Date
May 1, 2013, 08:25 UTC
Message-ID
<397ab75eeb9d1c60f418b1ded23d8de04cf16251.1367396752.git.john@keeping.me.uk>

When using "git subtree push" to split out a subtree and push it to a remote repository, we do not detect if the split command fails which causes the LHS of the refspec to be empty, deleting the remote branch.

Fix this by pulling the result of the split command into a variable so that we can die if the command fails.

Reported-by: Steffen Jaeckel <steffen.jaeckel@stzedn.de>
Signed-off-by: John Keeping <john@keeping.me.uk>
---
 contrib/subtree/git-subtree.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 8a23f58..10daa8b 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -715,7 +715,8 @@ cmd_push()
 	    repository=$1
 	    refspec=$2
 	    echo "git push using: " $repository $refspec
-	    git push $repository $(git subtree split --prefix=$prefix):refs/heads/$refspec
+	    localrev=$(git subtree split --prefix="$prefix") || die
+	    git push $repository $localrev:refs/heads/$refspec
 	else
 	    die "'$dir' must already exist. Try 'git subtree add'."
 	fi
-- 
1.8.3.rc0.149.g98a72f2.dirty
Next: Junio C Hamano
Message 1 of 2 in “contrib/subtree: don't delete remote branches if split fails”
  1. contrib/subtree: don't delete remote branches if split failsJohn Keeping, May 1, 2013
  2. Junio C HamanoMay 1, 2013

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.