diff options
-rwxr-xr-x | commit.d/50vcs-commit | 25 | ||||
-rw-r--r-- | debian/changelog | 2 |
2 files changed, 20 insertions, 7 deletions
diff --git a/commit.d/50vcs-commit b/commit.d/50vcs-commit index e7e0eaf..8a1ce3f 100755 --- a/commit.d/50vcs-commit +++ b/commit.d/50vcs-commit @@ -4,10 +4,21 @@ set -e message="$1" hostname=`hostname -f 2>/dev/null || hostname` +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 "$SUDO_USER" ]; then - export GIT_COMMITTER_NAME="$SUDO_USER" - export GIT_COMMITTER_EMAIL="$SUDO_USER@$hostname" + if [ -n "$USER" ]; then + export GIT_COMMITTER_NAME="$USER" + export GIT_COMMITTER_EMAIL="$USER@$hostname" fi if [ -n "$message" ]; then git commit $GIT_COMMIT_OPTIONS -m "$message" @@ -15,8 +26,8 @@ if [ "$VCS" = git ] && [ -d .git ]; then git commit $GIT_COMMIT_OPTIONS fi elif [ "$VCS" = hg ] && [ -d .hg ]; then - if [ -n "$SUDO_USER" ]; then - export LOGNAME="$SUDO_USER" + if [ -n "$USER" ]; then + export LOGNAME="$USER" fi if [ -n "$message" ]; then hg commit $HG_COMMIT_OPTIONS -m "$message" @@ -24,8 +35,8 @@ elif [ "$VCS" = hg ] && [ -d .hg ]; then hg commit $HG_COMMIT_OPTIONS fi elif [ "$VCS" = bzr ] && [ -d .bzr ]; then - if [ -n "$SUDO_USER" ]; then - export EMAIL="$SUDO_USER <$SUDO_USER@$hostname>" + if [ -n "$USER" ]; then + export EMAIL="$USER <$USER@$hostname>" BZR_AUTHOR='--author="root <root@$hostname>"' fi if [ -n "$message" ]; then diff --git a/debian/changelog b/debian/changelog index 90efae9..1323b2a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,8 @@ etckeeper (0.43) UNRELEASED; urgency=low is present, to avoid committing state in the middle of an apt run. Closes: #567538 * Add /etc/webmin/webmin/oscache to ignore list. Closes: #567255 + * Check owner of tty to determine who has su'd to root when committing, + based on a patch by Jakov Sosic. -- Joey Hess <joeyh@debian.org> Sun, 31 Jan 2010 14:36:44 -0500 |