the static git browser that builds this site
git clone https://git.lucas.co/gitsite.git
post-commit-push (1.1K)
1 #!/bin/sh
2 # post-commit hook: push the branch just committed to origin (GitHub).
3 #
4 # Installed into every repo in repos.conf by install-hooks.sh, as a symlink to
5 # this file, so there is one copy to edit. It makes a commit also the
6 # publishing step: without it, committing is local only and nothing reaches
7 # GitHub (or git.lucas.co, which mirrors GitHub hourly) until a manual push.
8 #
9 # It never forces. If the push is rejected -- the branch moved on GitHub, the
10 # network is down -- the commit stands and the message below says so; fix it
11 # with an ordinary git pull / git push. Nothing is pushed on a detached HEAD
12 # or while a rebase is replaying commits.
13
14 branch=$(git symbolic-ref --quiet --short HEAD) || exit 0
15 git_dir=$(git rev-parse --git-dir)
16 if [ -d "$git_dir/rebase-merge" ] || [ -d "$git_dir/rebase-apply" ]; then
17 exit 0
18 fi
19 git remote get-url origin >/dev/null 2>&1 || exit 0
20
21 if out=$(git push --quiet --set-upstream origin "$branch" 2>&1); then
22 echo "pushed $branch to origin"
23 else
24 echo "post-commit: push of $branch FAILED -- the commit is local only:" >&2
25 printf '%s\n' "$out" | sed 's/^/ /' >&2
26 fi
27 exit 0