Skip to content

Commit 7a29c35

Browse files
committed
add a protetive git hook for internal-only commits
1 parent fb2d42c commit 7a29c35

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

.githooks/pre-push

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
# Refuse to push the internal branch (or any commit descending from it) to
3+
# GitHub.
4+
# Install: just install-hooks
5+
6+
remote_url="$2"
7+
8+
if [[ "$remote_url" != *github.com* ]]; then
9+
exit 0
10+
fi
11+
12+
ZERO_SHA="0000000000000000000000000000000000000000"
13+
14+
while read -r local_ref local_sha _remote_ref _remote_sha; do
15+
[[ "$local_sha" == "$ZERO_SHA" ]] && continue
16+
17+
if [[ "$local_ref" == "refs/heads/internal" ]]; then
18+
echo "error: refusing to push 'internal' to GitHub" >&2
19+
echo " The internal branch contains private workloads." >&2
20+
exit 1
21+
fi
22+
23+
if git rev-parse --verify internal >/dev/null 2>&1; then
24+
if git merge-base --is-ancestor internal "$local_sha" 2>/dev/null; then
25+
echo "error: '$local_ref' descends from 'internal' — refusing to push to GitHub" >&2
26+
echo " This ref contains commits from the internal branch." >&2
27+
exit 1
28+
fi
29+
fi
30+
done
31+
32+
exit 0

justfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ _rechunk image:
2424
sudo podman rmi {{image}} {{image}}-rechunked || true
2525
echo "Rechunked {{image}}"
2626

27+
# Install git hooks from .githooks/ into .git/hooks/
28+
install-hooks:
29+
#!/usr/bin/env bash
30+
set -euo pipefail
31+
for hook in .githooks/*; do
32+
name=$(basename "$hook")
33+
install -m 0755 "$hook" ".git/hooks/$name"
34+
echo "installed .git/hooks/$name"
35+
done
36+
2737
# === Container image builds =================================================
2838

2939
build-minimal version=fedora_version rechunk="false":

0 commit comments

Comments
 (0)