#!/bin/shset -eu# if being run directly, add a dash of redif [ -t 1 ]; thentrap 'printf "\e[0m"' EXITprintf "\e[1;31m"fi# resolve to a sha, ensure validityreadonly commit="$(git rev-parse --verify "${1:-HEAD}^{commit}")"tmpdir="tmp/pre-push/${commit}"rm -rf "tmp/pre-push/${commit}"# unpack all of the changed files, plus the test/common/static-code from that commitchanged_files="$(git diff-tree --no-commit-id --no-renames --diff-filter=d --name-only -r "${commit}" --)"required_files="$(git cat-file -p "${commit}":test/common/static-code | sed -n 's/^# requires: //p') test/common/static-code"git archive --prefix="${tmpdir}/" "${commit}" -- ${changed_files} ${required_files} | tar x# check that node_modules always gets updated with package.jsonif [ -e "${tmpdir}/package.json" -a ! -e "${tmpdir}/node_modules" ]; thenecho 'not ok 0 /node-modules/update'echo '# package.json changed, but node_modules not updated'fi# if any of the following commands fail, the function# will abort, leaving the temp directory in place(unset -- $(env | sed -n '/^GIT_/{s/=.*//p}')cd "${tmpdir}"git init -qb main .git add .WITH_PARTIAL_TREE=1 test/common/static-code)# paranoia: make sure we delete what we think we willrm -rf "tmp/pre-push/${commit}"rmdir --ignore-fail-on-non-empty tmp/pre-push tmp