Skip to content

Commit 373a94d

Browse files
committed
Add a pre-push hook
This hook will prevent pushing with outdated `dist/` files. It has to be copied manually into `.git/hooks/`, by developers who want to benefit from it. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent c908ed9 commit 373a94d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pre-push.hook

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
3+
# This pre-push hook ensures that we only push branches with up to date files in `dist/`.
4+
#
5+
# While at it, it also ensures that it is itself up to date with `pre-push.hook`
6+
7+
die () {
8+
echo "$*" >&2
9+
exit 1
10+
}
11+
12+
git diff --no-index --quiet pre-push.hook "$(git rev-parse --git-path hooks/pre-push)" ||
13+
die 'The `pre-push` hook is not up to date with `pre-push.hook`'
14+
15+
git diff --quiet dist/ ||
16+
die '`dist/` is dirty'
17+
18+
if test 'npm run build && npm run package' != "$(git show -s --format=%s HEAD)"
19+
then
20+
echo "Verifying that dist/ is up to date" >&2
21+
npm run build &&
22+
npm run package &&
23+
if ! git diff --quiet dist/
24+
then
25+
echo "Committing dist/ because it was not up to date" >&2
26+
git commit -sm "npm run build && npm run package" dist/
27+
fi
28+
fi

0 commit comments

Comments
 (0)