chiark / gitweb /
Makefile: Use $(wildcard) for commands_in
[topgit.git] / tg-create.sh
index d196e4f..3f33fa8 100644 (file)
@@ -15,7 +15,7 @@ while [ -n "$1" ]; do
        arg="$1"; shift
        case "$arg" in
        -*)
-               echo "Usage: tg create [-d DEPS...] NAME" >&2
+               echo "Usage: tg create NAME [DEPS...]" >&2
                exit 1;;
        *)
                if [ -z "$name" ]; then
@@ -31,18 +31,17 @@ done
 
 deps="${deps# }"
 if [ -z "$deps" ]; then
-       head="$(git symbolic-ref HEAD)"
-       bname="${head#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="$bname"
                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"
@@ -59,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
@@ -69,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
 
 
@@ -83,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
@@ -95,10 +96,11 @@ 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%> *}>"
@@ -107,7 +109,8 @@ author_addr="${author%> *}>"
        ! header="$(git config topgit.to)" || echo "To: $header"
        ! header="$(git config topgit.cc)" || echo "Cc: $header"
        ! header="$(git config topgit.bcc)" || echo "Bcc: $header"
-       echo "Subject: [PATCH] $1"
+       ! subject_prefix="$(git config topgit.subjectprefix)" || subject_prefix="$subject_prefix "
+       echo "Subject: [${subject_prefix}PATCH] $name"
        echo
        cat <<EOT
 <patch description>
@@ -115,7 +118,7 @@ author_addr="${author%> *}>"
 Signed-off-by: $author_addr
 EOT
 } >"$root_dir/.topmsg"
-git add "$root_dir/.topmsg"
+git add -f "$root_dir/.topmsg"