summaryrefslogtreecommitdiff
path: root/git
diff options
context:
space:
mode:
authorWilliam Gibb <william.gibb@mandiant.com>2014-06-26 11:21:55 -0400
committerWilliam Gibb <william.gibb@mandiant.com>2014-06-26 11:21:55 -0400
commitd9fc8b6c06b91dfddb73d18eaa8164e64cc2600a (patch)
tree261aed087e3abc7c43773d5133dd8adaeda1d524 /git
parent4a0ad305883201b6b3e68494fc70089180389f6e (diff)
downloadgitpython-d9fc8b6c06b91dfddb73d18eaa8164e64cc2600a.tar.gz
Add patch from to 0.3 branch.
https://github.com/gitpython-developers/GitPython/commit/f362d10fa24395c21b1629923ccd705ba73ae996 Related to #43
Diffstat (limited to 'git')
-rw-r--r--git/util.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/git/util.py b/git/util.py
index 7c257b37..88a72c0c 100644
--- a/git/util.py
+++ b/git/util.py
@@ -22,6 +22,10 @@ from gitdb.util import (
to_bin_sha
)
+# Import the user database on unix based systems
+if os.name == "posix":
+ import pwd
+
__all__ = ( "stream_copy", "join_path", "to_native_path_windows", "to_native_path_linux",
"join_path_native", "Stats", "IndexFileSHA1Writer", "Iterable", "IterableList",
"BlockingLockFile", "LockFile", 'Actor', 'get_user_id', 'assure_directory_exists',
@@ -113,12 +117,17 @@ def assure_directory_exists(path, is_file=False):
def get_user_id():
""":return: string identifying the currently active system user as name@node
- :note: user can be set with the 'USER' environment variable, usually set on windows"""
- ukn = 'UNKNOWN'
- username = os.environ.get('USER', os.environ.get('USERNAME', ukn))
- if username == ukn and hasattr(os, 'getlogin'):
- username = os.getlogin()
- # END get username from login
+ :note: user can be set with the 'USER' environment variable, usually set on windows
+ :note: on unix based systems you can use the password database
+ to get the login name of the effective process user"""
+ if os.name == "posix":
+ username = pwd.getpwuid(os.geteuid()).pw_name
+ else:
+ ukn = 'UNKNOWN'
+ username = os.environ.get('USER', os.environ.get('USERNAME', ukn))
+ if username == ukn and hasattr(os, 'getlogin'):
+ username = os.getlogin()
+ # END get username from login
return "%s@%s" % (username, platform.node())
#} END utilities