]> oss.titaniummirror.com Git - git-utils.git/blobdiff - git-publish-branch
Add Makefile to install and uninstall git utils
[git-utils.git] / git-publish-branch
index fb38886c16154a11cbd52297fd46602266a89412..74584e60b255513ed8aeecf4f1178fb4f64d2749 100755 (executable)
@@ -1,10 +1,14 @@
 #!/bin/sh
-# git-publish-branch [-d] <branch> [repository]
+# 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
@@ -13,11 +17,11 @@ unset remote
 if [ $# -eq 1 ]; then
     branch=$1
 elif [ $# -eq 2 ]; then
-    remote=$1
-    branch=$2
+    branch=$1
+    remote=$2
 elif [ $# -gt 2 ]; then
-    echo "Usage: $0 [<repository>] <branch>" >&2
-    exit 127
+    echo "Usage: $0 [branch] [repository]" >&2
+    exit 1
 fi
 
 if [ -z "$branch" ]; then
@@ -47,16 +51,37 @@ 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 "$0: no local branch $branch" >&2
-       exit 127
+       echo "no local branch $branch" >&2
+       exit 1
     elif [ -n "$remote_ref" ]; then
-       echo "$0: $remote already has branch $branch" >&2
-       exit 127
+       echo "$remote already has branch $branch" >&2
+       exit 1
     elif [ -n "$remote_config" ]; then
-       echo "$0: local branch $branch is already a tracking branch" >&2
-       exit 127
+       echo "local branch $branch is already a tracking branch" >&2
+       exit 1
     fi
 
     git push "$remote" "$branch:refs/heads/$branch"