tg-summary.sh: Clean up printing status columns
[topgit/greenrd.git] / tg-create.sh
blob30c69c9ee1929ba80af155e46e704c4e339f7d73
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz> 2008
4 # GPLv2
6 deps= # List of dependent branches
7 restarted= # Set to 1 if we are picking up in the middle of base setup
8 merge= # List of branches to be merged; subset of $deps
9 name=
12 ## Parse options
14 while [ -n "$1" ]; do
15 arg="$1"; shift
16 case "$arg" in
17 -d)
18 deps="$(echo "$1" | sed 's/,/ /g')"; shift;;
19 -*)
20 echo "Usage: tg create [-d DEPS...] NAME" >&2
21 exit 1;;
23 [ -z "$name" ] || die "name already specified ($name)"
24 name="$arg";;
25 esac
26 done
29 ## Auto-guess dependencies
31 if [ -z "$deps" ]; then
32 head="$(git symbolic-ref HEAD)"
33 bname="${head#refs/top-bases/}"
34 if [ "$bname" != "$head" -a -s "$git_dir/top-deps" -a -s "$git_dir/top-merge" ]; then
35 # We are on a base branch now; resume merge!
36 deps="$(cat "$git_dir/top-deps")"
37 merge="$(cat "$git_dir/top-merge")"
38 name="$bname"
39 restarted=1
40 info "Resuming $name setup..."
41 else
42 # The common case
43 [ -z "$name" ] && die "no branch name given"
44 deps="${head#refs/heads/}"
45 [ "$deps" != "$head" ] || die "refusing to auto-depend on non-head ref ($head)"
46 info "Automatically marking dependency on $deps"
50 [ -n "$merge" -o -n "$restarted" ] || merge="$deps "
52 for d in $deps; do
53 git rev-parse --verify "$d" >/dev/null 2>&1 ||
54 die "unknown branch dependency '$d'"
55 done
56 ! git rev-parse --verify "$name" >/dev/null 2>&1 ||
57 die "branch '$name' already exists"
59 # Clean up any stale stuff
60 rm -f "$git_dir/top-deps" "$git_dir/top-merge"
63 ## Create base
65 if [ -n "$merge" ]; then
66 # Unshift the first item from the to-merge list
67 branch="${merge%% *}"
68 merge="${merge#* }"
69 info "Creating $name base from $branch..."
70 switch_to_base "$name" "$branch"
74 ## Merge other dependencies into the base
76 while [ -n "$merge" ]; do
77 # Unshift the first item from the to-merge list
78 branch="${merge%% *}"
79 merge="${merge#* }"
80 info "Merging $name base with $branch..."
82 if ! git merge "$branch"; then
83 info "Please commit merge resolution and call: tg create"
84 info "It is also safe to abort this operation using \`git reset --hard\`"
85 info "but please remember you are on the base branch now;"
86 info "you will want to switch to a different branch."
87 echo "$deps" >"$git_dir/top-deps"
88 echo "$merge" >"$git_dir/top-merge"
89 exit 2
91 done
94 ## Set up the topic branch
96 git checkout -b "$name"
98 echo "$deps" | sed 's/ /\n/g' >"$root_dir/.topdeps"
99 git add "$root_dir/.topdeps"
101 author="$(git var GIT_AUTHOR_IDENT)"
102 author_addr="${author%> *}>"
104 echo "From: $author_addr"
105 echo "Subject: [PATCH] $1"
106 echo
107 cat <<EOT
108 <patch description>
110 Signed-off-by: $author_addr
112 } >"$root_dir/.topmsg"
113 git add "$root_dir/.topmsg"
117 info "Topic branch $name set up. Please fill .topmsg now and make initial commit."
118 info "To abort: git rm -f .top* && git checkout ${deps%% *} && tg delete $name"