1 #!/bin/sh 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 or stable/ 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 hashes=$(git show --format='%b' --quiet $commit_hash | sed -nr 's/^.cherry picked from commit (.*).$/\1/p') 18 checked=0 19 branches+="" 20 for hash in $hashes; do 21 branch=$(git branch -a --contains "$hash" 2>/dev/null| grep -oE '(master|stable/[a-z]+)') 22 if [ $? -ne 0 ]; then 23 echo "Cherry pick hash $hash not on any master or stable branches" 24 exit 1 25 fi 26 branches+=" $branch" 27 checked=$(($checked + 1)) 28 done 29 30 if [ $checked -eq 0 ]; then 31 if ! grep -q '^defaultbranch=stable/' .gitreview; then 32 echo "Checked $checked cherry-pick hashes: OK" 33 exit 0 34 else 35 if ! git show --format='%B' --quiet $commit_hash | grep -qi 'stable.*only'; then 36 echo 'Stable branch requires either cherry-pick -x headers or [stable-only] tag!' 37 exit 1 38 fi 39 fi 40 else 41 echo Checked $checked cherry-pick hashes on branches: $(echo $branches | tr ' ' '\n' | sort | uniq) 42 fi