1#!/bin/bash 2 3# Copyright JS Foundation and other contributors, http://js.foundation 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17# Usage 18function print_usage 19{ 20 echo "Usage: $0 [--help] [--tolerant] [--travis]" 21} 22 23function print_help 24{ 25 echo "$0: Check Signed-off-by message of the latest commit" 26 echo "" 27 print_usage 28 echo "" 29 echo "Optional arguments:" 30 echo " --help print this help message" 31 echo " --tolerant check the existence of the message only but don't" 32 echo " require the name and email address to match the author" 33 echo " of the commit" 34 echo " --travis perform check in tolerant mode if on Travis CI and not" 35 echo " checking a pull request, perform strict check otherwise" 36 echo "" 37 echo "The last line of every commit message must follow the form of:" 38 echo "'JerryScript-DCO-1.0-Signed-off-by: NAME EMAIL', where NAME and EMAIL must" 39 echo "match the name and email address of the author of the commit (unless in" 40 echo "tolerant mode)." 41} 42 43# Processing command line 44TOLERANT="no" 45while [ "$#" -gt 0 ] 46do 47 if [ "$1" == "--help" ] 48 then 49 print_help 50 exit 0 51 elif [ "$1" == "--tolerant" ] 52 then 53 TOLERANT="yes" 54 shift 55 elif [ "$1" == "--travis" ] 56 then 57 if [ "$TRAVIS_PULL_REQUEST" == "" ] 58 then 59 echo -e "\e[1;33mWarning! Travis-tolerant mode requested but not running on Travis CI! \e[0m" 60 elif [ "$TRAVIS_PULL_REQUEST" == "false" ] 61 then 62 TOLERANT="yes" 63 else 64 TOLERANT="no" 65 fi 66 shift 67 else 68 print_usage 69 exit 1 70 fi 71done 72 73# Determining latest commit 74parent_hashes=(`git show -s --format=%p HEAD | head -1`) 75 76if [ "${#parent_hashes[@]}" -eq 1 ] 77then 78 commit_hash=`git show -s --format=%h HEAD | head -1` 79elif [ "${#parent_hashes[@]}" -eq 2 ] 80then 81 commit_hash=${parent_hashes[1]} 82else 83 echo "$0: cannot handle commit with ${#parent_hashes[@]} parents ${parent_hashes[@]}" 84 exit 1 85fi 86 87# Checking the last line 88actual_signed_off_by_line=`git show -s --format=%B $commit_hash | sed '/^$/d' | tr -d '\015' | tail -n 1` 89 90if [ "$TOLERANT" == "no" ] 91then 92 author_name=`git show -s --format=%an $commit_hash` 93 author_email=`git show -s --format=%ae $commit_hash` 94 required_signed_off_by_line="JerryScript-DCO-1.0-Signed-off-by: $author_name $author_email" 95 96 if [ "$actual_signed_off_by_line" != "$required_signed_off_by_line" ] 97 then 98 echo -e "\e[1;33mSigned-off-by message is incorrect. The following line should be at the end of the $commit_hash commit's message: '$required_signed_off_by_line'. \e[0m" 99 exit 1 100 fi 101else 102 echo -e "\e[1;33mWarning! The name and email address of the author of the $commit_hash commit is not checked in tolerant mode! \e[0m" 103 if echo "$actual_signed_off_by_line" | grep -q -v '^JerryScript-DCO-1.0-Signed-off-by:' 104 then 105 echo -e "\e[1;33mSigned-off-by message is incorrect. The following line should be at the end of the $commit_hash commit's message: '$required_signed_off_by_line'. \e[0m" 106 exit 1 107 fi 108fi 109 110exit 0 111