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="${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"
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
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
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
## 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 <<EOT
<patch description>
Signed-off-by: $author_addr
EOT
} >"$root_dir/.topmsg"
-git add "$root_dir/.topmsg"
+git add -f "$root_dir/.topmsg"