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 echo "Usage: tg create [-d DEPS...] NAME" >&2
21 if [ -z "$name" ]; then
30 ## Auto-guess dependencies
33 if [ -z "$deps" ]; then
34 head="$(git symbolic-ref HEAD)"
35 bname
="${head#refs/top-bases/}"
36 if [ "$bname" != "$head" -a -s "$git_dir/top-deps" -a -s "$git_dir/top-merge" ]; then
37 # We are on a base branch now; resume merge!
38 deps
="$(cat "$git_dir/top-deps
")"
39 merge
="$(cat "$git_dir/top-merge
")"
42 info
"Resuming $name setup..."
45 [ -z "$name" ] && die
"no branch name given"
46 deps
="${head#refs/heads/}"
47 [ "$deps" != "$head" ] || die
"refusing to auto-depend on non-head ref ($head)"
48 info
"Automatically marking dependency on $deps"
52 [ -n "$merge" -o -n "$restarted" ] || merge
="$deps "
55 git rev-parse
--verify "$d" >/dev
/null
2>&1 ||
56 die
"unknown branch dependency '$d'"
58 ! git rev-parse
--verify "$name" >/dev
/null
2>&1 ||
59 die
"branch '$name' already exists"
61 # Clean up any stale stuff
62 rm -f "$git_dir/top-deps" "$git_dir/top-merge"
67 if [ -n "$merge" ]; then
68 # Unshift the first item from the to-merge list
71 info
"Creating $name base from $branch..."
72 switch_to_base
"$name" "$branch"
76 ## Merge other dependencies into the base
78 while [ -n "$merge" ]; do
79 # Unshift the first item from the to-merge list
82 info
"Merging $name base with $branch..."
84 if ! git merge
"$branch"; then
85 info
"Please commit merge resolution and call: tg create"
86 info
"It is also safe to abort this operation using \`git reset --hard\`"
87 info
"but please remember you are on the base branch now;"
88 info
"you will want to switch to a different branch."
89 echo "$deps" >"$git_dir/top-deps"
90 echo "$merge" >"$git_dir/top-merge"
96 ## Set up the topic branch
98 git checkout
-b "$name"
100 echo "$deps" |
sed 's/ /\n/g' >"$root_dir/.topdeps"
101 git add
"$root_dir/.topdeps"
103 author
="$(git var GIT_AUTHOR_IDENT)"
104 author_addr
="${author%> *}>"
106 echo "From: $author_addr"
107 ! header
="$(git config topgit.to)" ||
echo "To: $header"
108 ! header
="$(git config topgit.cc)" ||
echo "Cc: $header"
109 ! header
="$(git config topgit.bcc)" ||
echo "Bcc: $header"
110 echo "Subject: [PATCH] $1"
115 Signed-off-by: $author_addr
117 } >"$root_dir/.topmsg"
118 git add
"$root_dir/.topmsg"
122 info
"Topic branch $name set up. Please fill .topmsg now and make initial commit."
123 info
"To abort: git rm -f .top* && git checkout ${deps%% *} && tg delete $name"