8000 Add patch from to 0.3 branch. · williamgibb/GitPython@d9fc8b6 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d9fc8b6

Browse files
author
William Gibb
committed
Add patch from to 0.3 branch.
gitpython-developers@f362d10 Related to gitpython-developers#43
1 parent 4a0ad30 commit d9fc8b6

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

git/util.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
to_bin_sha
2323
)
2424

25+
# Import the user database on unix based systems
26+
if os.name == "posix":
27+
import pwd
28+
2529
__all__ = ( "stream_copy", "join_path", "to_native_path_windows", "to_native_path_linux",
2630
"join_path_native", "Stats", "IndexFileSHA1Writer", "Iterable", "IterableList",
2731
"BlockingLockFile", "LockFile", 'Actor', 'get_user_id', 'assure_directory_exists',
@@ -113,12 +117,17 @@ def assure_directory_exists(path, is_file=False):
113117

114118
def get_user_id():
115119
""":return: string identifying the currently active system user as name@node
116-
:note: user can be set with the 'USER' environment variable, usually set on windows"""
117-
ukn = 'UNKNOWN'
118-
username = os.environ.get('USER', os.environ.get('USERNAME', ukn))
119-
if username == ukn and hasattr(os, 'getlogin'):
120-
username = os.getlogin()
121-
# END get username from login
120+
:note: user can be set with the 'USER' environment variable, usually set on windows
121+
:note: on unix based systems you can use the password database
122+
to get the login name of the effective process user"""
123+
if os.name == "posix":
124+
username = pwd.getpwuid(os.geteuid()).pw_name
125+
else:
126+
ukn = 'UNKNOWN'
127+
username = os.environ.get('USER', os.environ.get('USERNAME', ukn))
128+
if username == ukn and hasattr(os, 'getlogin'):
129+
username = os.getlogin()
130+
# END get username from login
122131
return "%s@%s" % (username, platform.node())
123132

124133
#} END utilities

0 commit comments

Comments
 (0)
0