 fcd1195b09
			
		
	
	fcd1195b09
	
	
	
		
			
			This is a follow up to change I8e4e5afc773d53dee9c1c24951bb07a45ddc2f1a which fixed an issue with validation when the topmost patch after a Zuul rebase is a merge patch. We need to also use the $commit_hash variable for the check for stable-only patches, else it will incorrectly fail because it is checking the merge patch's commit message. Change-Id: Ia725346b65dd5e2f16aa049c74b45d99e22b3524 (cherry picked from commit1e10461c71) (cherry picked from commitf1e4f6b078) (cherry picked from commite676a48054) (cherry picked from commit115b43ed3e) (cherry picked from commitcde42879a4) (cherry picked from commit3c77443550) (cherry picked from commit70cbd1535a)
		
			
				
	
	
		
			43 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/bin/sh
 | |
| #
 | |
| # A tool to check the cherry-pick hashes from the current git commit message
 | |
| # to verify that they're all on either master or stable/ branches
 | |
| #
 | |
| 
 | |
| commit_hash=""
 | |
| 
 | |
| # Check if the patch is a merge patch by counting the number of parents.
 | |
| # If the patch has 2 parents, then the 2nd parent is the patch we want
 | |
| # to validate.
 | |
| parent_number=$(git show --format='%P' --quiet | awk '{print NF}')
 | |
| if [ $parent_number -eq 2 ]; then
 | |
|     commit_hash=$(git show --format='%P' --quiet | awk '{print $NF}')
 | |
| fi
 | |
| 
 | |
| hashes=$(git show --format='%b' --quiet $commit_hash | sed -nr 's/^.cherry picked from commit (.*).$/\1/p')
 | |
| checked=0
 | |
| branches+=""
 | |
| for hash in $hashes; do
 | |
|     branch=$(git branch -a --contains "$hash" 2>/dev/null| grep -oE '(master|stable/[a-z]+)')
 | |
|     if [ $? -ne 0 ]; then
 | |
|         echo "Cherry pick hash $hash not on any master or stable branches"
 | |
|         exit 1
 | |
|     fi
 | |
|     branches+=" $branch"
 | |
|     checked=$(($checked + 1))
 | |
| done
 | |
| 
 | |
| if [ $checked -eq 0 ]; then
 | |
|     if ! grep -q '^defaultbranch=stable/' .gitreview; then
 | |
|         echo "Checked $checked cherry-pick hashes: OK"
 | |
|         exit 0
 | |
|     else
 | |
|         if ! git show --format='%B' --quiet $commit_hash | grep -qi 'stable.*only'; then
 | |
|             echo 'Stable branch requires either cherry-pick -x headers or [stable-only] tag!'
 | |
|             exit 1
 | |
|         fi
 | |
|     fi
 | |
| else
 | |
|     echo Checked $checked cherry-pick hashes on branches: $(echo $branches | tr ' ' '\n' | sort | uniq)
 | |
| fi
 |