diff options
author | Joey Hess <joeyh@debian.org> | 2013-07-31 11:33:45 -0400 |
---|---|---|
committer | Joey Hess <joeyh@debian.org> | 2013-07-31 11:33:45 -0400 |
commit | fdeec420b54e252e611c353ce39fe61c924e3e7d (patch) | |
tree | 2a1974e6c8cc56263e3903f49ea2a841ea895c6d /commit.d/50vcs-commit |
etckeeper (1.7) unstable; urgency=low
* Fix hilarious typo hardcoding my name. Closes: #718425
# imported from the archive
Diffstat (limited to 'commit.d/50vcs-commit')
-rwxr-xr-x | commit.d/50vcs-commit | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/commit.d/50vcs-commit b/commit.d/50vcs-commit new file mode 100755 index 0000000..3a4c819 --- /dev/null +++ b/commit.d/50vcs-commit @@ -0,0 +1,104 @@ +#!/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 + if [ "x$1" = "x-m" ]; then + shift 1 + fi + echo "$1" > "$logfile" + fi +else + logfile="" +fi + +hostname=`hostname` +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 + # Use user.name and user.email from the gitconfig belonging + # to the user who became root. + USER_HOME="$(perl -e 'print ((getpwnam(shift()))[7])' "$USER")" + if [ -n "$USER_HOME" ] && [ -e "$USER_HOME/.gitconfig" ]; then + if [ -z "$GIT_AUTHOR_NAME" ]; then + GIT_AUTHOR_NAME="$(git config -f "$USER_HOME/.gitconfig" user.name)" || true + fi + if [ -z "$GIT_AUTHOR_EMAIL" ]; then + GIT_AUTHOR_EMAIL="$(git config -f "$USER_HOME/.gitconfig" user.email)" || true + fi + fi + if [ -z "$GIT_COMMITTER_EMAIL" ]; then + GIT_COMMITER_EMAIL="$(git config --global user.email)" || true + fi + + if [ -z "$GIT_AUTHOR_NAME" ]; then + export GIT_AUTHOR_NAME="$USER" + fi + if [ -z "$GIT_AUTHOR_EMAIL" ]; then + export GIT_AUTHOR_EMAIL="$USER@$hostname" + fi + if [ -z "$GIT_COMMITTER_EMAIL" ]; then + export GIT_COMMITTER_EMAIL=`whoami`"@$hostname" + fi + 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 [ -z "$EMAIL" ] && [ -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 |