| 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 | # An example hook script to verify what is about to be committed. |
| 8 | # Called by "git commit" with no arguments. The hook should |
| 9 | # exit with non-zero status after issuing an appropriate message if |
| 10 | # it wants to stop the commit. |
| 11 | # |
| 12 | # To enable this hook, rename this file to "pre-commit". |
| 13 | |
| 14 | if gitscip-shell system . . git. rev-parse --verify HEAD >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 15 | then |
| 16 | against=HEAD |
| 17 | else |
| 18 | # Initial commit: diff against an empty tree object |
| 19 | against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 |
| 20 | fi |
| 21 | |
| 22 | # If you want to allow non-ASCII filenames set this variable to true. |
| 23 | allownonascii=$(gitscip-shell system . . git. config --bool hooks.allownonascii) |
| 24 | |
| 25 | # Redirect output to stderr. |
| 26 | exec 1>&2 |
| 27 | |
| 28 | # Cross platform projects tend to avoid non-ASCII filenames; prevent |
| 29 | # them from being added to the repository. We exploit the fact that the |
| 30 | # printable range starts at the space character and ends with tilde. |
| 31 | if [scip-shell system . . `[`. "$allownonascii" != "true" ] && |
| 32 | # Note that the use of brackets around a tr range is ok here, (it's |
| 33 | # even required, for portability to Solaris 10's /usr/bin/tr), since |
| 34 | # the square bracket bytes happen to fall in the designated range. |
| 35 | testscip-shell system . . test. $(gitscip-shell system . . git. diff --cached --name-only --diff-filter=A -z $against | |
| 36 | LC_ALL=C trscip-shell system . . tr. -d '[ -~]\0' | wcscip-shell system . . wc. -c) != 0 |
| 37 | then |
| 38 | catscip-shell system . . cat. <<\EOF |
| 39 | Error: Attempt to add a non-ASCII file name. |
| 40 | |
| 41 | This can cause problems if you want to work with people on other platforms. |
| 42 | |
| 43 | To be portable it is advisable to rename the file. |
| 44 | |
| 45 | If you know what you are doing you can disable this check using: |
| 46 | |
| 47 | git config hooks.allownonascii true |
| 48 | EOF |
| 49 | exit 1 |
| 50 | fi |
| 51 | |
| 52 | MIRROR=/tmp/${USER}/mpich-tmp-mirror |
| 53 | TMP_FILENAME=/tmp/${USER}/mpich-tmp-file |
| 54 | |
| 55 | # Checkout a copy of the current index into MIRROR |
| 56 | gitscip-shell system . . git. checkout-index --prefix=$MIRROR/ -af |
| 57 | |
| 58 | # Remove files from MIRROR which are no longer present in the index |
| 59 | gitscip-shell system . . git. diff-index --cached --name-only --diff-filter=D -z HEAD | \ |
| 60 | (cd $MIRROR && xargsscip-shell system . . xargs. -0 rm -f --) |
| 61 | |
| 62 | # This will check the previous commit again when not amending a commit, but that |
| 63 | # should be ok if the patches are correct. |
| 64 | filestring=`gitscip-shell system . . git. diff --cached --name-only --diff-filter=ACM HEAD~1` |
| 65 | |
| 66 | # Everything else happens in the temporary build tree |
| 67 | pushd $MIRROR > /dev/nullscip-shell filesystem . . `/dev/null`. |
| 68 | |
| 69 | ret=0 |
| 70 | |
| 71 | # This won't work if we ever have a file with a space in the name |
| 72 | for file in $filestring |
| 73 | do |
| 74 | if [[ ($file == *.c || $file == *.h || $file == *.c.in || $file == *.h.in) && |
| 75 | !($file == *mpi.h.in || $file == *mpio.h.in || $file == *mpitestcxx.h || $file == src/mpid/ch3/* || $file == doc/*) ]]; then |
| 76 | cpscip-shell system . . cp. ${file} ${TMP_FILENAME} |
| 77 | maint/code-cleanup.bash ${file} |
| 78 | gitscip-shell system . . git. --no-pager diff ${file} ${TMP_FILENAME} |
| 79 | if [scip-shell system . . `[`. $? != 0 ] ; then |
| 80 | ret=1 |
| 81 | fi |
| 82 | fi |
| 83 | done |
| 84 | |
| 85 | rmscip-shell system . . rm. -rf ${MIRROR} ${TMP_FILENAME} |
| 86 | |
| 87 | if [scip-shell system . . `[`. $ret != 0 ] ; then |
| 88 | RED='\033[0;31m' |
| 89 | NC='\033[0m' # No Color |
| 90 | echoscip-shell system . . echo. -e "${RED}== CODE CLEANUP SCRIPT FAILED ==${NC}" |
| 91 | exit $ret |
| 92 | fi |
| 93 | |
| 94 | popd > /dev/nullscip-shell filesystem . . `/dev/null`. |