X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=topgit.git;a=blobdiff_plain;f=tg-create.sh;h=6e8490742282f86f4bebf1908b0e0504e6753e6e;hp=939af33b14e3d9941788e3d4426734e618e521bc;hb=c4c57a55aa1b825109f0ce0547994ad394812902;hpb=f27e69343eee27bba00aa897134dc89bf26687a2 diff --git a/tg-create.sh b/tg-create.sh index 939af33..6e84907 100644 --- a/tg-create.sh +++ b/tg-create.sh @@ -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# }" @@ -51,10 +68,10 @@ fi [ -n "$merge" -o -n "$restarted" ] || merge="$deps " for d in $deps; do - git rev-parse --verify "$d" >/dev/null 2>&1 || + ref_exists "$d" || die "unknown branch dependency '$d'" done -! git rev-parse --verify "$name" >/dev/null 2>&1 || +! ref_exists "$name" || die "branch '$name' already exists" # Clean up any stale stuff @@ -82,7 +99,7 @@ while [ -n "$merge" ]; do info "Merging $name base with $branch..." if ! git merge "$branch"; then - info "Please commit merge resolution and call: tg create" + info "Please commit merge resolution and call: $tg create" info "It is also safe to abort this operation using:" info "git reset --hard some_branch" info "(You are on a detached HEAD now.)" @@ -100,7 +117,7 @@ git update-ref "refs/top-bases/$name" "HEAD" "" git checkout -b "$name" echo "$deps" | sed 's/ /\n/g' >"$root_dir/.topdeps" -git add "$root_dir/.topdeps" +git add -f "$root_dir/.topdeps" author="$(git var GIT_AUTHOR_IDENT)" author_addr="${author%> *}>" @@ -118,9 +135,11 @@ author_addr="${author%> *}>" Signed-off-by: $author_addr EOT } >"$root_dir/.topmsg" -git add "$root_dir/.topmsg" +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" +info "To abort: git rm -f .top* && git checkout ${deps%% *} && $tg delete $name" + +# vim:noet