3 # Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
4 # Copyright 2016 University of Szeged
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
21 echo "Usage: $0 [--help] [--tolerant] [--travis]"
26 echo "$0: Check Signed-off-by message of the latest commit"
30 echo "Optional arguments:"
31 echo " --help print this help message"
32 echo " --tolerant check the existence of the message only but don't"
33 echo " require the name and email address to match the author"
35 echo " --travis perform check in tolerant mode if on Travis CI and not"
36 echo " checking a pull request, perform strict check otherwise"
38 echo "The last line of every commit message must follow the form of:"
39 echo "'IoT.js-DCO-1.0-Signed-off-by: NAME EMAIL', where NAME and EMAIL must"
40 echo "match the name and email address of the author of the commit (unless in"
41 echo "tolerant mode)."
44 # Processing command line
48 if [ "$1" == "--help" ]
52 elif [ "$1" == "--tolerant" ]
56 elif [ "$1" == "--travis" ]
58 if [ "$TRAVIS_PULL_REQUEST" == "" ]
60 echo -e "\e[1;33mWarning! Travis-tolerant mode requested but not running on Travis CI! \e[0m"
61 elif [ "$TRAVIS_PULL_REQUEST" == "false" ]
74 # Determining latest commit
75 parent_hashes=(`git show -s --format=%p HEAD | head -1`)
77 if [ "${#parent_hashes[@]}" -eq 1 ]
79 commit_hash=`git show -s --format=%h HEAD | head -1`
80 elif [ "${#parent_hashes[@]}" -eq 2 ]
82 commit_hash=${parent_hashes[1]}
84 echo "$0: cannot handle commit with ${#parent_hashes[@]} parents ${parent_hashes[@]}"
88 # Checking the last line
89 actual_signed_off_by_line=`git show -s --format=%B $commit_hash | sed '/^$/d' | tr -d '\015' | tail -n 1`
91 if [ "$TOLERANT" == "no" ]
93 author_name=`git show -s --format=%an $commit_hash`
94 author_email=`git show -s --format=%ae $commit_hash`
95 required_signed_off_by_line="IoT.js-DCO-1.0-Signed-off-by: $author_name $author_email"
97 if [ "$actual_signed_off_by_line" != "$required_signed_off_by_line" ]
99 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"
103 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"
104 if echo "$actual_signed_off_by_line" | grep -q -v '^IoT.js-DCO-1.0-Signed-off-by:'
106 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"