]> oss.titaniummirror.com Git - git-utils.git/commitdiff
Add a -f option to git-publish-branch
authorR. Steve McKown <rsmckown@gmail.com>
Thu, 8 Apr 2010 20:05:11 +0000 (14:05 -0600)
committerR. Steve McKown <rsmckown@gmail.com>
Thu, 8 Apr 2010 20:05:11 +0000 (14:05 -0600)
git-publish-branch
git-publish-branch.1

index 4986c363d9c5d3f02d61c1714e560c0acba7088b..74584e60b255513ed8aeecf4f1178fb4f64d2749 100755 (executable)
@@ -2,9 +2,13 @@
 # git-publish-branch [-d] [branch] [repository]
 
 unset delete
+unset force
 if [ "$1" = "-d" ]; then
     delete=1
     shift
+elif [ "$1" = "-f" ]; then
+    force=1
+    shift
 fi
 
 unset branch
@@ -47,6 +51,27 @@ if [ $delete ]; then
        git config --unset "branch.$branch.merge"
        git config --unset "branch.$branch"
     fi
+elif [ $force ]; then
+    if [ -z "$local_ref" ]; then
+       echo "no local branch $branch" >&2
+       exit 1
+    elif [ -z "$remote_ref" ]; then
+       echo "$remote has no branch $branch" >&2
+       exit 1
+    elif [ -z "$remote_config" ]; then
+       echo "local branch $branch is not a tracking branch" >&2
+       exit 1
+    fi
+
+    # Delete the remote branch
+    if [ -n "$remote_ref" ]; then
+       git push "$remote" ":refs/heads/$branch"
+    else
+       echo "$remote has to remote branch $branch" >&2
+    fi
+
+    # Push the new branch
+    git push "$remote" "+$branch:refs/heads/$branch"
 else
     if [ -z "$local_ref" ]; then
        echo "no local branch $branch" >&2
index 00a02f563994ab04c73bc22e9ea2bdcbb89defaf..502399e79fe1aa30b37db1390ca02666b4d3dff8 100644 (file)
@@ -4,23 +4,35 @@
 git-publish-branch \- publish a local branch to a remote repository
 
 .SH SYNOPSIS
-\fBgit-publish-branch\fR [-d] [\fIBRANCH\fR] [\fIREPOSITORY\fR]
+\fBgit-publish-branch\fR [-d] [-f] [\fIBRANCH\fR] [\fIREPOSITORY\fR]
 
 .SH "DESCRIPTION"
 
 .PP
 \fBgit-publish-branch\fR publishes a local branch to a remote repository.  The
 selected branch is pushed to the remote repository and the local branch is
-reset as a tracking branch for the new remote branch.
+reset as a tracking branch for the new remote branch.  Subsequent calls to
+\fBgit-publish-branch\fR peform fast-forward updates of the remote branch by
+pushing new commits in the local branch.
 
 If the -d option is specified, the branch is removed from the remote repository
 and the local branch is unset as its tracking branch.
 
+If the -f option is specified, allows a non-fast forward update of the remote
+branch, as supported by adding a '+' to the refspec on a git push command.
+BE CAREFUL, as this command will lose history on the remote branch.  The -f
+option is only suitable for pushing topic or temporary branches that are
+periodically rebased, and other users of the branch are aware of the
+consequences.
+
 .SH "OPTIONS"
 
 .TP
 -d
-Include this switch to delete (unpublish) a branch.
+Include this switch to delete (unpublish) a remote branch.
+
+-f
+Force a non-fast-forward update of the remote branch.
 
 .TP
 \fIBRANCH\fR