diff options
author | Joey Hess <joey@gnu.kitenet.net> | 2010-02-18 13:42:59 -0500 |
---|---|---|
committer | Joey Hess <joey@gnu.kitenet.net> | 2010-02-18 13:42:59 -0500 |
commit | 83bd7f6263e56fbdb6904efb47777bee5a64f38c (patch) | |
tree | 556899b599e780eb37d20e88475cf680d6f76126 /commit.d/50vcs-commit | |
parent | 1b3e3c99b714419ac4047cc8372b3478d5fc1d24 (diff) |
Check owner of tty to determine who has su'd to root when committing, based on a patch by Jakov Sosic.
Diffstat (limited to 'commit.d/50vcs-commit')
-rwxr-xr-x | commit.d/50vcs-commit | 25 |
1 files changed, 18 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 |