Merge #11597: [trivial] Fix error messages in CFeeBumper
[bitcoinplatinum.git] / contrib / devtools / commit-script-check.sh
blob1c9dbc7f68ff5355fa02848dd6c85d659cf8d409
1 #!/bin/sh
2 # Copyright (c) 2017 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 # This simple script checks for commits beginning with: scripted-diff:
7 # If found, looks for a script between the lines -BEGIN VERIFY SCRIPT- and
8 # -END VERIFY SCRIPT-. If no ending is found, it reads until the end of the
9 # commit message.
11 # The resulting script should exactly transform the previous commit into the current
12 # one. Any remaining diff signals an error.
14 if test "x$1" = "x"; then
15 echo "Usage: $0 <commit>..."
16 exit 1
19 RET=0
20 PREV_BRANCH=`git name-rev --name-only HEAD`
21 PREV_HEAD=`git rev-parse HEAD`
22 for i in `git rev-list --reverse $1`; do
23 if git rev-list -n 1 --pretty="%s" $i | grep -q "^scripted-diff:"; then
24 git checkout --quiet $i^ || exit
25 SCRIPT="`git rev-list --format=%b -n1 $i | sed '/^-BEGIN VERIFY SCRIPT-$/,/^-END VERIFY SCRIPT-$/{//!b};d'`"
26 if test "x$SCRIPT" = "x"; then
27 echo "Error: missing script for: $i"
28 echo "Failed"
29 RET=1
30 else
31 echo "Running script for: $i"
32 echo "$SCRIPT"
33 eval "$SCRIPT"
34 git --no-pager diff --exit-code $i && echo "OK" || (echo "Failed"; false) || RET=1
36 git reset --quiet --hard HEAD
37 else
38 if git rev-list "--format=%b" -n1 $i | grep -q '^-\(BEGIN\|END\)[ a-zA-Z]*-$'; then
39 echo "Error: script block marker but no scripted-diff in title"
40 echo "Failed"
41 RET=1
44 done
45 git checkout --quiet $PREV_BRANCH 2>/dev/null || git checkout --quiet $PREV_HEAD
46 exit $RET