Debian Codegraph @

tools/check-cherry-picks.sh

raw symbols SCIP
1 #!/bin/bash
2 #
3 # A tool to check the cherry-pick hashes from the current git commit message
4 # to verify that they're all on either master, stable/ or unmaintained/ branches
5 #
6
7 commit_hash=""
8
9 # Check if the patch is a merge patch by counting the number of parents.
10 # If the patch has 2 parents, then the 2nd parent is the patch we want
11 # to validate.
12 parent_number=$(git show --format='%P' --quiet | awk '{print NF}')
13 if [ $parent_number -eq 2 ]; then
14 commit_hash=$(git show --format='%P' --quiet | awk '{print $NF}')
15 fi
16
17 if git show --format='%aE' --quiet ${commit_hash} | grep -qi '[email protected]'; then
18 echo 'Bot generated change; ignoring'
19 exit 0
20 fi
21
22 hashes=$(git show --format='%b' --quiet ${commit_hash} | sed -nr 's/^.cherry picked from commit (.*).$/\1/p')
23 checked=0
24 branches+=""
25 for hash in $hashes; do
26 branch=$(git branch -a --contains "$hash" 2>/dev/null| grep -oE '(master|stable/[a-z0-9.]+|unmaintained/[a-z0-9.]+)')
27 if [ $? -ne 0 ]; then
28 branch=$(git tag --contains "$hash" 2>/dev/null| grep -oE '([0-9.]+-eol)')
29 if [ $? -ne 0 ]; then
30 echo "Cherry pick hash $hash not on any master, stable, unmaintained or EOL'd branches"
31 exit 1
32 fi
33 fi
34 branches+=" $branch"
35 checked=$(($checked + 1))
36 done
37
38 if [ $checked -eq 0 ]; then
39 if ! grep -qE '^defaultbranch=(stable|unmaintained)/' .gitreview; then
40 echo "Checked $checked cherry-pick hashes: OK"
41 exit 0
42 else
43 if ! git show --format='%B' --quiet ${commit_hash} | grep -qi 'stable.*only'; then
44 echo 'Stable branch requires either cherry-pick -x headers or [stable-only] tag!'
45 exit 1
46 fi
47 fi
48 else
49 echo Checked $checked cherry-pick hashes on branches: $(echo $branches | tr ' ' '\n' | sort | uniq)
50 fi