chiark / gitweb /
[TOPGIT] allow working with annihilated branches
[topgit.git] / tg-create.sh
index fee7dff3ee9fdf5d1e29c31282cf73abdc9f7067..6e8490742282f86f4bebf1908b0e0504e6753e6e 100644 (file)
@@ -7,6 +7,7 @@ deps= # List of dependent branches
 restarted= # Set to 1 if we are picking up in the middle of base setup
 merge= # List of branches to be merged; subset of $deps
 name=
+rname= # Remote branch to base this one on
 
 
 ## Parse options
@@ -14,8 +15,10 @@ name=
 while [ -n "$1" ]; do
        arg="$1"; shift
        case "$arg" in
+       -r)
+               rname="$1"; shift;;
        -*)
-               echo "Usage: tg [...] create NAME [DEPS...]" >&2
+               echo "Usage: tg [...] create NAME [DEPS...|-r RNAME]" >&2
                exit 1;;
        *)
                if [ -z "$name" ]; then
@@ -27,6 +30,20 @@ while [ -n "$1" ]; do
 done
 
 
+## Fast-track creating branches based on remote ones
+
+if [ -n "$rname" ]; then
+       [ -n "$name" ] || die "no branch name given"
+       ! ref_exists "$name" || die "branch '$name' already exists"
+       has_remote "$rname" || die "no branch $rname in remote $base_remote"
+
+       git update-ref "refs/top-bases/$name" "refs/remotes/$base_remote/top-bases/$rname"
+       git update-ref "refs/heads/$name" "refs/remotes/$base_remote/$rname"
+       info "Topic branch $name based on $base_remote : $rname set up."
+       exit 0
+fi
+
+
 ## Auto-guess dependencies
 
 deps="${deps# }"
@@ -124,3 +141,5 @@ git add -f "$root_dir/.topmsg"
 
 info "Topic branch $name set up. Please fill .topmsg now and make initial commit."
 info "To abort: git rm -f .top* && git checkout ${deps%% *} && $tg delete $name"
+
+# vim:noet