-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathreceive-pack
More file actions
executable file
·52 lines (47 loc) · 2.12 KB
/
Copy pathreceive-pack
File metadata and controls
executable file
·52 lines (47 loc) · 2.12 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env bash
#
# Example objgitd receive-pack hook.
#
# objgitd runs this script after a successful push when started with
# -allow-hooks. It does NOT run on a normal `git` server — it only has meaning
# when this repository is served by objgitd.
#
# Execution environment (see CLAUDE.md "Push hooks"):
# * It runs in a kefka virtual shell, NOT a real OS shell. Only kefka's
# built-in commands are available (coreutils: cat, ls, echo, printf, head,
# tail, cut, sort, uniq, wc, sha256sum, grep, ...). There is no PATH to
# system binaries, no network, and no `git`.
# * /src is a READ-ONLY checkout of the pushed commit. The working directory
# starts here.
# * /tmp is the only writable location (also $HOME and $TMPDIR). Writing
# anywhere else fails; a redirect into /src aborts the script.
# * The hook runs asynchronously after the push response, so it cannot reject
# a push. Its stdout/stderr and exit status are written to the server log
# only — the person pushing never sees them.
# * One run happens per created or updated branch. Branch deletions are
# skipped.
#
# These variables describe the ref that triggered this run:
# OBJGIT_REPO repository path, e.g. /myproject.git
# OBJGIT_SERVICE always "receive-pack"
# OBJGIT_REF full ref name, e.g. refs/heads/main
# OBJGIT_BRANCH short branch name, e.g. main
# OBJGIT_OLD_SHA previous tip (all zeros when the branch was created)
# OBJGIT_NEW_SHA new tip
# git's usual "<old> <new> <ref>" line is also fed on stdin.
echo "push to ${OBJGIT_REPO} ${OBJGIT_REF}: ${OBJGIT_OLD_SHA} -> ${OBJGIT_NEW_SHA}"
# /src is the checkout of the new commit. List what landed at the top level.
echo "top-level contents:"
ls /src
# Read a file out of the push and act on it.
if [ -f /src/go.mod ]; then
module="$(head -n 1 /src/go.mod | cut -d' ' -f2)"
echo "go module: ${module}"
fi
# Scratch work goes in /tmp. Here we record a tiny build manifest.
manifest=/tmp/manifest.txt
echo "ref ${OBJGIT_REF}" > "${manifest}"
echo "sha ${OBJGIT_NEW_SHA}" >> "${manifest}"
echo "manifest (${manifest}):"
cat "${manifest}"
echo "hook done"