| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | |
| 3 | set -eu |
| 4 | |
| 5 | # if being run directly, add a dash of red |
| 6 | if [scip-shell system . . `[`. -t 1 ]; then |
| 7 | trap 'printf "\e[0m"' EXIT |
| 8 | printfscip-shell system . . printf. "\e[1;31m" |
| 9 | fi |
| 10 | |
| 11 | # resolve to a sha, ensure validity |
| 12 | readonly commit="$(gitscip-shell system . . git. rev-parse --verify "${1:-HEAD}^{commit}")" |
| 13 | |
| 14 | tmpdir="tmp/pre-push/${commit}" |
| 15 | rmscip-shell system . . rm. -rf "tmp/pre-push/${commit}" |
| 16 | |
| 17 | # unpack all of the changed files, plus the test/common/static-code from that commit |
| 18 | changed_files="$(gitscip-shell system . . git. diff-tree --no-commit-id --no-renames --diff-filter=d --name-only -r "${commit}" --)" |
| 19 | required_files="$(gitscip-shell system . . git. cat-file -p "${commit}":test/common/static-code | sedscip-shell system . . sed. -n 's/^# requires: //p') test/common/static-code" |
| 20 | gitscip-shell system . . git. archive --prefix="${tmpdir}/" "${commit}" -- ${changed_files} ${required_files} | tarscip-shell system . . tar. x |
| 21 | |
| 22 | # check that node_modules always gets updated with package.json |
| 23 | if [scip-shell system . . `[`. -e "${tmpdir}/package.json" -a ! -e "${tmpdir}/node_modules" ]; then |
| 24 | echoscip-shell system . . echo. 'not ok 0 /node-modules/update' |
| 25 | echoscip-shell system . . echo. '# package.json changed, but node_modules not updated' |
| 26 | fi |
| 27 | |
| 28 | # if any of the following commands fail, the function |
| 29 | # will abort, leaving the temp directory in place |
| 30 | ( |
| 31 | unset -- $(envscip-shell system . . env. | sedscip-shell system . . sed. -n '/^GIT_/{s/=.*//p}scip-shell filesystem . . `/^GIT_/{s/=.*//p}`.') |
| 32 | cd "${tmpdir}" |
| 33 | gitscip-shell system . . git. init -qb main . |
| 34 | gitscip-shell system . . git. add . |
| 35 | WITH_PARTIAL_TREE=1 test/common/static-code |
| 36 | ) |
| 37 | |
| 38 | # paranoia: make sure we delete what we think we will |
| 39 | rmscip-shell system . . rm. -rf "tmp/pre-push/${commit}" |
| 40 | rmdirscip-shell system . . rmdir. --ignore-fail-on-non-empty tmp/pre-push tmp |