blob: 497917bbef5ba03c7700d5ab0aa98d06e54e054a [file] [log] [blame]
Fabio Utzig5b989102017-09-04 16:27:51 -03001#!/bin/bash
2
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15MAIN_BRANCH=master
16
17# ignores last commit because travis/gh creates a merge commit
Fabio Utzig5101b0f2017-09-06 21:50:52 -030018commits=$(git log --format=%h ${MAIN_BRANCH}..HEAD | tail -n +2)
Fabio Utzig5b989102017-09-04 16:27:51 -030019
Fabio Utzig31180172017-09-06 21:38:14 -030020has_commits=false
Fabio Utzig5b989102017-09-04 16:27:51 -030021for sha in $commits; do
Fabio Utzig0b561382017-09-07 17:04:26 -030022 author="Signed-off-by: $(git show -s --format="%an <%ae>" ${sha})"
23 committer="Signed-off-by: $(git show -s --format="%cn <%ce>" ${sha})"
24
Fabio Utzig31180172017-09-06 21:38:14 -030025 lines="$(git show -s --format=%B ${sha})"
Fabio Utzig0b561382017-09-07 17:04:26 -030026
27 found_author=false
28 found_committer=false
Fabio Utzig31180172017-09-06 21:38:14 -030029 IFS=$'\n'
30 for line in ${lines}; do
31 stripped=$(echo $line | sed -e 's/^\s*//' | sed -e 's/\s*$//')
Fabio Utzig0b561382017-09-07 17:04:26 -030032 if [[ ${stripped} == ${author} ]]; then
33 found_author=true
Fabio Utzig31180172017-09-06 21:38:14 -030034 fi
Fabio Utzig0b561382017-09-07 17:04:26 -030035 if [[ ${stripped} == ${committer} ]]; then
36 found_committer=true
37 fi
38
39 [[ ${found_author} == true && ${found_committer} == true ]] && break
Fabio Utzig31180172017-09-06 21:38:14 -030040 done
Fabio Utzig5b989102017-09-04 16:27:51 -030041
Fabio Utzig0b561382017-09-07 17:04:26 -030042 if [[ ${found_author} == false || ${found_committer} == false ]]; then
43 echo -e "One or more \"Signed-off-by\" lines missing in commit ${sha}"
Fabio Utzig5b989102017-09-04 16:27:51 -030044 exit 1
45 fi
Fabio Utzig31180172017-09-06 21:38:14 -030046
47 has_commits=true
Fabio Utzig5b989102017-09-04 16:27:51 -030048done
Fabio Utzig31180172017-09-06 21:38:14 -030049
50if [[ ${has_commits} = false ]]; then
51 echo "No commits found in this PR!"
52 exit 1
53fi