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 NAME [DEPS...]" >&2
21 if [ -z "$name" ]; then
30 ## Auto-guess dependencies
33 if [ -z "$deps" ]; then
34 if [ -z "$name" -a -s "$git_dir/top-name" -a -s "$git_dir/top-deps" -a -s "$git_dir/top-merge" ]; then
35 # We are setting up the base branch now; resume merge!
36 name
="$(cat "$git_dir/top-name
")"
37 deps
="$(cat "$git_dir/top-deps
")"
38 merge
="$(cat "$git_dir/top-merge
")"
40 info
"Resuming $name setup..."
43 [ -z "$name" ] && die
"no branch name given"
44 head="$(git symbolic-ref HEAD)"
45 deps
="${head#refs/heads/}"
46 [ "$deps" != "$head" ] || die
"refusing to auto-depend on non-head ref ($head)"
47 info
"Automatically marking dependency on $deps"
51 [ -n "$merge" -o -n "$restarted" ] || merge
="$deps "
55 die
"unknown branch dependency '$d'"
57 ! ref_exists
"$name" ||
58 die
"branch '$name' already exists"
60 # Clean up any stale stuff
61 rm -f "$git_dir/top-name" "$git_dir/top-deps" "$git_dir/top-merge"
66 if [ -n "$merge" ]; then
67 # Unshift the first item from the to-merge list
70 info
"Creating $name base from $branch..."
71 # We create a detached head so that we can abort this operation
72 git checkout
-q "$(git rev-parse "$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:"
87 info
"git reset --hard some_branch"
88 info
"(You are on a detached HEAD now.)"
89 echo "$name" >"$git_dir/top-name"
90 echo "$deps" >"$git_dir/top-deps"
91 echo "$merge" >"$git_dir/top-merge"
97 ## Set up the topic branch
99 git update-ref
"refs/top-bases/$name" "HEAD" ""
100 git checkout
-b "$name"
102 echo "$deps" |
sed 's/ /\n/g' >"$root_dir/.topdeps"
103 git add
-f "$root_dir/.topdeps"
105 author
="$(git var GIT_AUTHOR_IDENT)"
106 author_addr
="${author%> *}>"
108 echo "From: $author_addr"
109 ! header
="$(git config topgit.to)" ||
echo "To: $header"
110 ! header
="$(git config topgit.cc)" ||
echo "Cc: $header"
111 ! header
="$(git config topgit.bcc)" ||
echo "Bcc: $header"
112 ! subject_prefix
="$(git config topgit.subjectprefix)" || subject_prefix
="$subject_prefix "
113 echo "Subject: [${subject_prefix}PATCH] $name"
118 Signed-off-by: $author_addr
120 } >"$root_dir/.topmsg"
121 git add
-f "$root_dir/.topmsg"
125 info
"Topic branch $name set up. Please fill .topmsg now and make initial commit."
126 info
"To abort: git rm -f .top* && git checkout ${deps%% *} && tg delete $name"