]> git.lizzy.rs Git - rust.git/blob - src/tools/cherry-pick.sh
Rollup merge of #103283 - nbarrios1337:unsafe-impl-suggestions, r=cjgillot
[rust.git] / src / tools / cherry-pick.sh
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