threads / patch / 33692

patchcontrib/subtree: don't delete remote branches if split fails

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

## tl;dr

2 messages between May 1, 2013 and May 1, 2013. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

John Keeping· May 1, 2013, 08:25 UTC · lore

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(-)
Show changes to contrib/subtree/git-subtree.sh +2 −1
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
Junio C Hamano· May 1, 2013, 17:13 UTC · re: John Keeping · lore

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

John Keeping <john@keeping.me.uk> writes:
Show 27 quoted lines
> 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
Looks trivially correct to me.

← back to recent threads