Fabio Utzig | 5b98910 | 2017-09-04 16:27:51 -0300 | [diff] [blame] | 1 | #!/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 | |
| 15 | MAIN_BRANCH=master |
| 16 | |
| 17 | # ignores last commit because travis/gh creates a merge commit |
Fabio Utzig | 5101b0f | 2017-09-06 21:50:52 -0300 | [diff] [blame] | 18 | commits=$(git log --format=%h ${MAIN_BRANCH}..HEAD | tail -n +2) |
Fabio Utzig | 5b98910 | 2017-09-04 16:27:51 -0300 | [diff] [blame] | 19 | |
Fabio Utzig | 3118017 | 2017-09-06 21:38:14 -0300 | [diff] [blame] | 20 | has_commits=false |
Fabio Utzig | 5b98910 | 2017-09-04 16:27:51 -0300 | [diff] [blame] | 21 | for sha in $commits; do |
Fabio Utzig | 0b56138 | 2017-09-07 17:04:26 -0300 | [diff] [blame^] | 22 | 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 Utzig | 3118017 | 2017-09-06 21:38:14 -0300 | [diff] [blame] | 25 | lines="$(git show -s --format=%B ${sha})" |
Fabio Utzig | 0b56138 | 2017-09-07 17:04:26 -0300 | [diff] [blame^] | 26 | |
| 27 | found_author=false |
| 28 | found_committer=false |
Fabio Utzig | 3118017 | 2017-09-06 21:38:14 -0300 | [diff] [blame] | 29 | IFS=$'\n' |
| 30 | for line in ${lines}; do |
| 31 | stripped=$(echo $line | sed -e 's/^\s*//' | sed -e 's/\s*$//') |
Fabio Utzig | 0b56138 | 2017-09-07 17:04:26 -0300 | [diff] [blame^] | 32 | if [[ ${stripped} == ${author} ]]; then |
| 33 | found_author=true |
Fabio Utzig | 3118017 | 2017-09-06 21:38:14 -0300 | [diff] [blame] | 34 | fi |
Fabio Utzig | 0b56138 | 2017-09-07 17:04:26 -0300 | [diff] [blame^] | 35 | if [[ ${stripped} == ${committer} ]]; then |
| 36 | found_committer=true |
| 37 | fi |
| 38 | |
| 39 | [[ ${found_author} == true && ${found_committer} == true ]] && break |
Fabio Utzig | 3118017 | 2017-09-06 21:38:14 -0300 | [diff] [blame] | 40 | done |
Fabio Utzig | 5b98910 | 2017-09-04 16:27:51 -0300 | [diff] [blame] | 41 | |
Fabio Utzig | 0b56138 | 2017-09-07 17:04:26 -0300 | [diff] [blame^] | 42 | if [[ ${found_author} == false || ${found_committer} == false ]]; then |
| 43 | echo -e "One or more \"Signed-off-by\" lines missing in commit ${sha}" |
Fabio Utzig | 5b98910 | 2017-09-04 16:27:51 -0300 | [diff] [blame] | 44 | exit 1 |
| 45 | fi |
Fabio Utzig | 3118017 | 2017-09-06 21:38:14 -0300 | [diff] [blame] | 46 | |
| 47 | has_commits=true |
Fabio Utzig | 5b98910 | 2017-09-04 16:27:51 -0300 | [diff] [blame] | 48 | done |
Fabio Utzig | 3118017 | 2017-09-06 21:38:14 -0300 | [diff] [blame] | 49 | |
| 50 | if [[ ${has_commits} = false ]]; then |
| 51 | echo "No commits found in this PR!" |
| 52 | exit 1 |
| 53 | fi |