##// END OF EJS Templates
windows: gracefully handle when the username cannot be determined...
Matt Harbison -
r50414:80541972 stable
parent child Browse files
Show More
@@ -581,7 +581,13 b' def username(uid=None):'
581 581
582 582 If uid is None, return the name of the current user."""
583 583 if not uid:
584 return pycompat.fsencode(getpass.getuser())
584 try:
585 return pycompat.fsencode(getpass.getuser())
586 except ModuleNotFoundError:
587 # getpass.getuser() checks for a few environment variables first,
588 # but if those aren't set, imports pwd and calls getpwuid(), none of
589 # which exists on Windows.
590 pass
585 591 return None
586 592
587 593
@@ -14,4 +14,18 b''
14 14 tip 3:a49829c4fc11
15 15 t1 0:f7b1eb17ad24
16 16
17 Ensure that the username access fails gracefully if assumptions about the
18 environment made by python do not hold.
19
20 #if windows
21 >>> import os
22 >>> from mercurial import util
23 >>> os.environ.pop('LOGNAME', None) and None
24 >>> os.environ.pop('USER', None) and None
25 >>> os.environ.pop('LNAME', None) and None
26 >>> os.environ.pop('USERNAME', None) and None
27 >>> print(util.username())
28 None
29 #endif
30
17 31 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now