| 1 | #! /usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | ## |
| 3 | ## Copyright (C) by Argonne National Laboratory |
| 4 | ## See COPYRIGHT in top-level directory |
| 5 | ## |
| 6 | |
| 7 | # This script is used for CI testing, to use -- |
| 8 | # git rebase --verbose --exec maint/hooks/spellchecker [base-commit] |
| 9 | |
| 10 | # Redirect output to stderr. |
| 11 | exec 1>&2 |
| 12 | |
| 13 | MIRROR=/tmp/${USER}/mpich-spellchecker-$$ |
| 14 | TMP_FILENAME=/tmp/${USER}/mpich-tmp-$$ |
| 15 | |
| 16 | # Checkout a copy of the current index into MIRROR |
| 17 | gitscip-shell system . . git. checkout-index --prefix=$MIRROR/ -af |
| 18 | |
| 19 | # Remove files from MIRROR which are no longer present in the index |
| 20 | gitscip-shell system . . git. diff-index --cached --name-only --diff-filter=D -z HEAD | \ |
| 21 | (cd $MIRROR && xargsscip-shell system . . xargs. -0 rm -f --) |
| 22 | |
| 23 | # This will check the previous commit again when not amending a commit, but that |
| 24 | # should be ok if the patches are correct. |
| 25 | filestring=`gitscip-shell system . . git. diff --cached --name-only --diff-filter=ACM HEAD~1` |
| 26 | |
| 27 | # Everything else happens in the temporary build tree |
| 28 | pushd $MIRROR > /dev/nullscip-shell filesystem . . `/dev/null`. |
| 29 | |
| 30 | ret=0 |
| 31 | |
| 32 | # check commit message |
| 33 | gitscip-shell system . . git. log --format=%B -n 1 HEAD > commit-message |
| 34 | cpscip-shell system . . cp. commit-message ${TMP_FILENAME} |
| 35 | bashscip-shell system . . bash. maint/spellcheck.sh commit-message |
| 36 | diffscip-shell system . . diff. commit-message ${TMP_FILENAME} |
| 37 | if [scip-shell system . . `[`. $? != 0 ] ; then |
| 38 | ret=1 |
| 39 | fi |
| 40 | rmscip-shell system . . rm. -f commit-message |
| 41 | |
| 42 | # This won't work if we ever have a file with a space in the name |
| 43 | for file in $filestring |
| 44 | do |
| 45 | if [[ -f $file && $file != *.tex ]]; then |
| 46 | cpscip-shell system . . cp. -p ${file} ${TMP_FILENAME} |
| 47 | output=$(bashscip-shell system . . bash. maint/spellcheck.sh ${file}) |
| 48 | diffs=$(gitscip-shell system . . git. --no-pager diff ${file} ${TMP_FILENAME}) |
| 49 | if testscip-shell system . . test. -n "$output" -o -n "$diffs" ; then |
| 50 | echoscip-shell system . . echo. "$output" |
| 51 | echoscip-shell system . . echo. "$diffs" |
| 52 | ret=1 |
| 53 | fi |
| 54 | fi |
| 55 | done |
| 56 | |
| 57 | popd > /dev/nullscip-shell filesystem . . `/dev/null`. |
| 58 | |
| 59 | rmscip-shell system . . rm. -rf ${MIRROR} ${TMP_FILENAME} |
| 60 | |
| 61 | if [scip-shell system . . `[`. $ret != 0 ] ; then |
| 62 | RED='\033[0;31m' |
| 63 | NC='\033[0m' # No Color |
| 64 | echoscip-shell system . . echo. -e "${RED}== SPELLCHECKER SCRIPT FAILED ==${NC}" |
| 65 | exit $ret |
| 66 | fi |