Skip to content

Commit 425caed

Browse files
committed
get_user_id: use EUID instead of getpass.getuser() to resolve users
fixes gitpython-developers#1577
1 parent e3bc5d1 commit 425caed

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

git/util.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
from .compat import is_win
1010
import contextlib
1111
from functools import wraps
12-
import getpass
1312
import logging
1413
import os
1514
import platform
15+
import pwd
1616
import subprocess
1717
import re
1818
import shutil
@@ -410,7 +410,8 @@ def is_cygwin_git(git_executable: Union[None, PathLike]) -> bool:
410410

411411
def get_user_id() -> str:
412412
""":return: string identifying the currently active system user as name@node"""
413-
return "%s@%s" % (getpass.getuser(), platform.node())
413+
user = pwd.getpwuid(os.geteuid()).pw_name
414+
return "%s@%s" % (user, platform.node())
414415

415416

416417
def finalize_process(proc: Union[subprocess.Popen, "Git.AutoInterrupt"], **kwargs: Any) -> None:
@@ -750,7 +751,7 @@ def _main_actor(
750751
config_reader: Union[None, "GitConfigParser", "SectionConstraint"] = None,
751752
) -> "Actor":
752753
actor = Actor("", "")
753-
user_id = None # We use this to avoid multiple calls to getpass.getuser()
754+
user_id = None # We use this to avoid multiple calls to resolve the user
754755

755756
def default_email() -> str:
756757
nonlocal user_id

0 commit comments

Comments
 (0)