summaryrefslogtreecommitdiffstats
path: root/git/bin/git-whoami
blob: 9cab9bce1d375c4432897ec58835b73c94cdc363 (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
#!/bin/sh

# git-whoami
# Author: Peter Eisentraut <peter@eisentraut.org>
# Created: 2011-10-27
# License: WTFPL; see http://sam.zoy.org/wtfpl/

# exact logic in ident.c in git source tree

set -e

get_email() {
	git config user.email || ( [ -n "$EMAIL" ] && echo "$EMAIL" ) || echo "$(id -nu)@$(hostname --fqdn)"
}

get_name() {
	git config user.name || getent passwd $(id -un) | cut -d : -f 5 | cut -d , -f 1
}

: ${GIT_AUTHOR_NAME=$(get_name)}
: ${GIT_COMMITTER_NAME=$(get_name)}
: ${GIT_AUTHOR_EMAIL=$(get_email)}
: ${GIT_COMMITTER_EMAIL=$(get_email)}

author="$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"
commit="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"

if [ "$author" = "$commit" ]; then
	echo "$author"
else
	echo "Author: $author"
	echo "Commit: $commit"
fi