2 # TopGit - A different patch queue manager
3 # Copyright (C) Petr Baudis <pasky@suse.cz> 2008
4 # Copyright (C) Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> 2008
5 # Copyright (C) Kyle J. McKay <mackyle@gmail.com> 2015
15 USAGE
="Usage: ${tgname:-tg} [...] import [-d <base-branch>] ([-p <prefix>] <range>... | -s <name> <commit>)"
25 branch_prefix
="$1"; shift;;
29 printf '%s\n' "$USAGE" >&2
32 ranges
="$ranges $arg"; rangecnt
=$
(( $rangecnt + 1 ));;
45 ! header
="$(git config topgit.to)" || headers
="$headers%nTo: $header"
46 ! header
="$(git config topgit.cc)" || headers
="$headers%nCc: $header"
47 ! header
="$(git config topgit.bcc)" || headers
="$headers%nBcc: $header"
48 git log
-1 --pretty=format
:"From: %an <%ae>$headers%nSubject: [PATCH] %s%n%n%b" "$commit"
53 # nice sed script from git-format-patch.sh
64 git log
-1 --pretty=format
:"%s" "$commit" |
sed -e "$titleScript"
67 origbasedep
="$basedep"
76 info
"---- Importing $commit to $branch_name"
77 lastsymref
="$(git symbolic-ref --quiet HEAD || :)"
78 lasthead
="$(git rev-parse --verify --quiet HEAD -- 2>/dev/null || :)"
79 $tg create
--no-edit "$branch_name" $basedep
81 get_commit_msg
"$commit" > .topmsg
82 git add
-f .topmsg .topdeps
83 if [ -n "$tgnosequester" ]; then
84 info
"topgit.sequester is set to false, unadvisedly skipping sequester commit"
86 git commit
-m "tg import create $branch_name"
88 if ! git cherry-pick
--no-commit "$commit"; then
89 info
"The commit will also finish the import of this patch."
92 git
-c topgit.sequester
=false commit
-C "$commit"
93 info
"++++ Importing $commit finished"
97 if [ -n "$single" ]; then
98 process_commit
$ranges "$single"
102 handle_pick_failure
()
104 # The import got stuck! Let the user fix it up.
105 info
"You are in a subshell."
106 info
"Please commit the cherry-pick resolution and then \`exit\`"
107 info
"If you want to abort the cherry-pick,"
108 info
"use \`exit 1\` to abort the tg import process at this point."
109 info
"Use \`exit 2\` to skip importing this commit and continue."
110 if ! "${SHELL:-@SHELL_PATH@}" -i </dev
/tty
; then
112 if [ $ret -eq 2 ]; then
113 info
"Ok, I will try to continue without importing this commit."
114 if [ -n "$tgnosequester" ]; then
115 git
reset --hard HEAD
117 git
reset --hard HEAD^
119 [ -z "$isfirst" ] || basedep
="$(origbasedep)"
120 [ -z "$lasthead" ] || git update-ref
--no-deref HEAD
"$lasthead"
121 [ -z "$lastsymref" ] || git symbolic-ref HEAD
"$lastsymref"
122 git update-ref
-d "refs/top-bases/$branch_name" ||
:
123 git update-ref
-d "refs/heads/$branch_name" ||
:
124 git
reset --hard HEAD
127 info
"Ok, you aborted the import operation at this point. Now, you just need"
128 info
"to switch back to some sane branch using \`git$gitcdopt checkout\`."
138 info
"Merged already: $comment"
141 if ! process_commit
"$rev" "$branch_prefix$(get_branch_name "$rev")"; then
143 [ -z "$islast" ] ||
return $ret
150 # nice arg verification stolen from git-format-patch.sh
153 for revpair
in $ranges; do
154 rangeidx
=$
(( $rangeidx + 1 ))
157 rev1
=`expr "z$revpair" : 'z\(.*\)\.\.'`
158 rev2
=`expr "z$revpair" : 'z.*\.\.\(.*\)'`
161 die
"Unknown range spec $revpair"
164 git rev-parse
--verify "$rev1^0" -- >/dev
/null
2>&1 ||
165 die
"Not a valid rev $rev1 ($revpair)"
166 git rev-parse
--verify "$rev2^0" -- >/dev
/null
2>&1 ||
167 die
"Not a valid rev $rev2 ($revpair)"
168 git cherry
-v "$rev1" "$rev2" |
{
169 if read sign
rev comment
; then
170 while read next_sign next_rev next_comment
; do
174 comment
="$next_comment"
176 [ "$rangeidx" != "$rangecnt" ] || islast
=1