X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=topgit.git;a=blobdiff_plain;f=tg-create.sh;h=3f33fa83d69472e44f7100ffc477f8035cf81fcb;hp=b5c7789315b6d6448b407ab2370013ebbd34a62c;hb=10ee8496b64f56b4a8bd32632ecd3dc4f66c2140;hpb=308892d0c071135031994606170c8be6653e7197 diff --git a/tg-create.sh b/tg-create.sh index b5c7789..3f33fa8 100644 --- a/tg-create.sh +++ b/tg-create.sh @@ -14,33 +14,34 @@ name= while [ -n "$1" ]; do arg="$1"; shift case "$arg" in - -d) - deps="$(echo "$1" | sed 's/,/ /g')"; shift;; -*) - echo "Usage: tg create [-d DEPS...] NAME" >&2 + echo "Usage: tg create NAME [DEPS...]" >&2 exit 1;; *) - [ -z "$name" ] || die "name already specified ($name)" - name="$arg";; + if [ -z "$name" ]; then + name="$arg" + else + deps="$deps $arg" + fi;; esac done ## Auto-guess dependencies +deps="${deps# }" if [ -z "$deps" ]; then - head="$(git symbolic-ref HEAD)" - bname="${heads#refs/top-bases/}" - if [ "$bname" != "$head" -a -s "$git_dir/top-deps" -a -s "$git_dir/top-merge" ]; then - # We are on a base branch now; resume merge! + if [ -z "$name" -a -s "$git_dir/top-name" -a -s "$git_dir/top-deps" -a -s "$git_dir/top-merge" ]; then + # We are setting up the base branch now; resume merge! + name="$(cat "$git_dir/top-name")" deps="$(cat "$git_dir/top-deps")" - merge="$(cat "$git_dir/top-merge") " - name="$base" + merge="$(cat "$git_dir/top-merge")" restarted=1 info "Resuming $name setup..." else # The common case [ -z "$name" ] && die "no branch name given" + head="$(git symbolic-ref HEAD)" deps="${head#refs/heads/}" [ "$deps" != "$head" ] || die "refusing to auto-depend on non-head ref ($head)" info "Automatically marking dependency on $deps" @@ -57,7 +58,7 @@ done die "branch '$name' already exists" # Clean up any stale stuff -rm -f "$git_dir/top-deps" "$git_dir/top-merge" +rm -f "$git_dir/top-name" "$git_dir/top-deps" "$git_dir/top-merge" ## Create base @@ -67,7 +68,8 @@ if [ -n "$merge" ]; then branch="${merge%% *}" merge="${merge#* }" info "Creating $name base from $branch..." - switch_to_base "$name" "$branch" + # We create a detached head so that we can abort this operation + git checkout -q "$(git rev-parse "$branch")" fi @@ -81,9 +83,10 @@ while [ -n "$merge" ]; do if ! git merge "$branch"; then info "Please commit merge resolution and call: tg create" - info "It is also safe to abort this operation using \`git reset --hard\`" - info "but please remember you are on the base branch now;" - info "you will want to switch to a different branch." + info "It is also safe to abort this operation using:" + info "git reset --hard some_branch" + info "(You are on a detached HEAD now.)" + echo "$name" >"$git_dir/top-name" echo "$deps" >"$git_dir/top-deps" echo "$merge" >"$git_dir/top-merge" exit 2 @@ -93,16 +96,21 @@ done ## Set up the topic branch +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%> *}>" { echo "From: $author_addr" - echo "Subject: [PATCH] $1" + ! header="$(git config topgit.to)" || echo "To: $header" + ! header="$(git config topgit.cc)" || echo "Cc: $header" + ! header="$(git config topgit.bcc)" || echo "Bcc: $header" + ! subject_prefix="$(git config topgit.subjectprefix)" || subject_prefix="$subject_prefix " + echo "Subject: [${subject_prefix}PATCH] $name" echo cat < @@ -110,9 +118,9 @@ 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 successfully set up. Please fill .topmsg now." -info "You MUST do an initial commit. To abort: git rm -f .top* && git checkout ${deps%% *} && tg delete $name" +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"