dev log: New git hooks
Published: 2025-04-05
Just want to give a quick update on my infra setup. After getting tired of doing scp to update my site and blog, I decided to use a git hook for that.The result is a super simple git hook that updates the files changed on the commit, and for the files in www folder copy them to the git page. I know this is kinda the other way, normally those files go to the server, but in my setup they live among the git files:
terminal.pink/ |-- HEAD |-- aims.pdf |-- bach-keynote.pdf |-- bach-thesis.pdf |-- blog | |-- HEAD | |-- branches | |-- config | |-- description | |-- hooks | | |-- post-receive | | |-- post-update | |-- index.html | |-- info | | |-- exclude | | `-- refs | |-- objects ... |-- index.html |-- index.br |-- index.gz ... |-- lin0 | |-- HEAD | |-- branches | |-- config ...
So using the www for those files makes it more clear that they are special ones. That let's me run my server and git under the same root, this the same URL.
This is the hook, use it as you please:
#!/bin/sh OUT="$HOME/terminal.pink" OPTS="--no-commit-id --no-renames --name-status --root -r" update() { echo "updating files with $1" while read -r op f do echo "$op $f" echo "$f" | grep -q "/" && \\ mkdir -p "$OUT/${f%/*}" > /dev/null # the rest is copied to my blog case "$op" in "D") rm -rf "$OUT/$f" ;; "A"|"C"|"M") git cat-file -p "$1:$f" > "$OUT/$f" ;; esac done <<- EOF $(git diff-tree $OPTS "$1") EOF } echo "starting post-receive" while read oldrev newrev ref do case "$ref" in "refs/heads/main") update "$newrev" ;; esac done echo "done"
The hook for this blog is just slightly different.