Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/ui.py @ 6862:7192876ac329
ui: add an option to prompt for the username when it isn't provided
When ui.askusername is set and not username are specified on the command line,
in hgrc or in the variables $HGUSER or $EMAIL, then hg will prompt for the
username.
Feature requested, and documentation provided by Mark Edgington.
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Wed, 06 Aug 2008 15:10:05 +0200 |
parents | f67d1468ac50 |
children | 8dca507e56ce |
comparison
equal
deleted
inserted
replaced
6861:0b6f2fa5e03f | 6862:7192876ac329 |
---|---|
329 def username(self): | 329 def username(self): |
330 """Return default username to be used in commits. | 330 """Return default username to be used in commits. |
331 | 331 |
332 Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL | 332 Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL |
333 and stop searching if one of these is set. | 333 and stop searching if one of these is set. |
334 If not found, use ($LOGNAME or $USER or $LNAME or | 334 If not found and ui.askusername is True, ask the user, else use |
335 $USERNAME) +"@full.hostname". | 335 ($LOGNAME or $USER or $LNAME or $USERNAME) + "@full.hostname". |
336 """ | 336 """ |
337 user = os.environ.get("HGUSER") | 337 user = os.environ.get("HGUSER") |
338 if user is None: | 338 if user is None: |
339 user = self.config("ui", "username") | 339 user = self.config("ui", "username") |
340 if user is None: | 340 if user is None: |
341 user = os.environ.get("EMAIL") | 341 user = os.environ.get("EMAIL") |
342 if user is None and self.configbool("ui", "askusername"): | |
343 user = self.prompt(_("Enter a commit username:"), default=None) | |
342 if user is None: | 344 if user is None: |
343 try: | 345 try: |
344 user = '%s@%s' % (util.getuser(), socket.getfqdn()) | 346 user = '%s@%s' % (util.getuser(), socket.getfqdn()) |
345 self.warn(_("No username found, using '%s' instead\n") % user) | 347 self.warn(_("No username found, using '%s' instead\n") % user) |
346 except KeyError: | 348 except KeyError: |