Skip to content

Commit adc8cd3

Browse files
author
Mukund Lakshman
committed
Add cherry-pick.sh convenience script.
1 parent 700b64e commit adc8cd3

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/tools/cherry-pick.sh

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
print_error() {
6+
echo "Error: \`$1\` is not a valid commit. To debug, run:"
7+
echo
8+
echo " git rev-parse --verify $1"
9+
echo
10+
}
11+
12+
full_sha() {
13+
git rev-parse \
14+
--verify \
15+
--quiet \
16+
"$1^{object}" || print_error $1
17+
}
18+
19+
commit_message_with_backport_note() {
20+
message=$(git log --format=%B -n 1 $1)
21+
echo $message | awk "NR==1{print; print \"\n(backport-of: $1)\"} NR!=1"
22+
}
23+
24+
cherry_pick_commit() {
25+
sha=$(full_sha $1)
26+
git cherry-pick $sha > /dev/null
27+
git commit \
28+
--amend \
29+
--file <(commit_message_with_backport_note $sha)
30+
}
31+
32+
for arg ; do
33+
cherry_pick_commit $arg
34+
done

0 commit comments

Comments
 (0)