2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz> 2008
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
18 deps
="$(echo "$1" | sed 's/,/ /g')"; shift;;
20 echo "Usage: tg create [-d DEPS...] NAME" >&2
23 [ -z "$name" ] || die
"name already specified ($name)"
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
")"
40 info
"Resuming $name setup..."
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 "
53 git rev-parse
--verify "$d" >/dev
/null
2>&1 ||
54 die
"unknown branch dependency '$d'"
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"
65 if [ -n "$merge" ]; then
66 # Unshift the first item from the to-merge list
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
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"
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"
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"