Mercurial > public > mercurial-scm > hg-stable
diff mercurial/windows.py @ 49426:805419729e11 stable
windows: gracefully handle when the username cannot be determined
This assumes implementation details, but I don't see any other way than to check
the environment variables ourselves (which would miss out on any future
enhancements that Python may make). This was originally reported as
https://foss.heptapod.net/mercurial/tortoisehg/thg/-/issues/5835.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 10 Oct 2022 11:28:19 -0400 |
parents | a75b530cfc29 |
children | 8147abc05794 |
line wrap: on
line diff
--- a/mercurial/windows.py Tue Oct 04 14:33:31 2022 +0200 +++ b/mercurial/windows.py Mon Oct 10 11:28:19 2022 -0400 @@ -581,7 +581,13 @@ If uid is None, return the name of the current user.""" if not uid: - return pycompat.fsencode(getpass.getuser()) + try: + return pycompat.fsencode(getpass.getuser()) + except ModuleNotFoundError: + # getpass.getuser() checks for a few environment variables first, + # but if those aren't set, imports pwd and calls getpwuid(), none of + # which exists on Windows. + pass return None