summaryrefslogtreecommitdiff
path: root/bin/post-commit
blob: 489181faf5560ab4ebace00dcf9d5efa66b0b174 (plain)
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
#!/usr/bin/env bash
# Copyright 2016-2017 Luke Shumaker
set -e

main() {
	branch=$(git name-rev --name-only HEAD)
	if [[ $branch == master ]]; then
		gitdir="$(git rev-parse --git-dir)"
		workdir="${gitdir}/pre-generated"
		exec 8>"${workdir}.lock"
		flock 8

		rm -rf -- "$workdir"
		git worktree prune
		git branch -D pre-generated.tmp &>/dev/null || true

		git worktree add -b pre-generated.tmp "${gitdir}/pre-generated" master
		(
			unset GIT_DIR GIT_WORK_TREE
			cd "$workdir"
			msg="$(git log -n1 master --pretty=format:%B)"

			make -j1
			echo '!/out/' >> .gitignore

			git add .
			git commit -m "make: $msg"
			git merge --no-edit -s ours pre-generated
			git checkout pre-generated
			git merge pre-generated.tmp
			git branch -d pre-generated.tmp
		)
		rm -rf -- "$workdir"
		git worktree prune
	fi
}

main &>/dev/tty &