File: git-hook-post-commit

package info (click to toggle)
cockpit 354-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 308,956 kB
  • sloc: javascript: 775,606; python: 40,351; ansic: 35,655; cpp: 11,117; sh: 3,511; makefile: 580; xml: 261
file content (40 lines) | stat: -rwxr-xr-x 1,363 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh

set -eu

# if being run directly, add a dash of red
if [ -t 1 ]; then
    trap 'printf "\e[0m"' EXIT
    printf "\e[1;31m"
fi

# resolve to a sha, ensure validity
readonly 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 commit
changed_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.json
if [ -e "${tmpdir}/package.json" -a ! -e "${tmpdir}/node_modules" ]; then
    echo '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 will
rm -rf "tmp/pre-push/${commit}"
rmdir --ignore-fail-on-non-empty tmp/pre-push tmp