summaryrefslogtreecommitdiff
path: root/contrib/post-merge-hook
blob: 66d006a19aed54f50d679b26f4d63511bcc785e8 (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
39
40
41
42
43
44
#!/bin/sh
#
# git post-merge (and post-checkout) hook, used by propellor's author to
# maintain a joeyconfig branch with some changes while being able to merge
# between it and branches without the changes.
#
# Each time this hook is run, it checks if it's on a branch with
# name ending in "config". If so, config.hs is pointed at $branch.hs
# and privdata/relocate is written to make files in privdata/.$branch/ be
# used.
# 
# Otherwise, config.hs is pointed at config-simple.hs, and
# privdata/relocate is removed.

set -e

commit () {
	if [ -n "$(git status --short privdata/relocate config.hs)" ]; then
		git commit -m "$1"
	fi
}

branch="$(git symbolic-ref --short HEAD)"
case "$branch" in
	"")
		true
		;;
	*config)
		ln -sf "$branch".hs config.hs
		git add config.hs
		echo ".$branch" > privdata/relocate
		git add privdata/relocate
		commit "setting up $branch after merge"
		;;
	*)
		ln -sf config-simple.hs config.hs
		git add config.hs
		if [ -e privdata/relocate ]; then
			rm -f privdata/relocate
			git rm --quiet privdata/relocate
		fi
		commit "clean up after merge"
		;;
esac