summaryrefslogtreecommitdiff
path: root/commit.d/50vcs-commit
blob: 197655f21ab4232d3b428ed56990323403a1eb59 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh
set -e

cleanup () {
	if [ -n "$logfile" ]; then
		rm -f "$logfile"
	fi
}
if [ -n "$1" ]; then
	trap cleanup EXIT
	logfile="$(mktemp -t etckeeper-$VCS.XXXXXXXXXX)"
	if [ "x$1" = "x--stdin" ]; then
		cat > "$logfile"
	else
		echo "$1" > "$logfile"
	fi
else
	logfile=""
fi

hostname=`hostname`
dnsdomainname=`dnsdomainname 2>/dev/null || true`
if [ -n "$dnsdomainname" ]; then
	hostname="$hostname.$dnsdomainname"
fi

USER=
if [ -n "$SUDO_USER" ]; then
	USER="$SUDO_USER"
else
	# try to check tty ownership, in case user su'd to root
	TTY="$(tty 2>/dev/null || true)"
	if [ -n "$TTY" ] && [ -c "$TTY" ]; then
		USER="$(find "$TTY" -printf "%u")"
	fi
fi

if [ "$VCS" = git ] && [ -d .git ]; then
	if [ -n "$USER" ]; then
		export GIT_AUTHOR_NAME="$USER"
		export GIT_AUTHOR_EMAIL="$USER@$hostname"
	fi
	if [ -n "$logfile" ]; then
		git commit $GIT_COMMIT_OPTIONS -F "$logfile"
	else
		git commit $GIT_COMMIT_OPTIONS
	fi
elif [ "$VCS" = hg ] && [ -d .hg ]; then
	if [ -n "$USER" ]; then
		export LOGNAME="$USER"
	fi
	if [ -z "$HGUSER" ]; then
		export HGUSER="$USER@$hostname"
	fi
	if [ -n "$logfile" ]; then
		hg commit $HG_COMMIT_OPTIONS -l "$logfile"
	else
		hg commit $HG_COMMIT_OPTIONS
	fi
elif [ "$VCS" = bzr ] && [ -d .bzr ]; then
	if [ -n "$USER" ]; then
		export EMAIL="$USER <$USER@$hostname>"
	fi
	if [ -n "$logfile" ]; then
		bzr commit $BZR_COMMIT_OPTIONS -F "$logfile"
	else
		bzr commit $BZR_COMMIT_OPTIONS
	fi
elif [ "$VCS" = darcs ] && [ -d _darcs ]; then
	if [ -z "$USER" ]; then
		USER=root
	fi
	if [ -n "$logfile" ]; then
		darcs record --author="$USER" $DARCS_COMMIT_OPTIONS --logfile="$logfile"
	else
		darcs record --author="$USER" $DARCS_COMMIT_OPTIONS
	fi
fi