Commits

Yuya Nishihara  committed 3619f14

qtlib: make sure getCurrentUsername() not fall back to system value

If not ui.interactive(), ui.username() does not fail even if username is
unconfigured. Thus, getCurrentUsername() cannot detect missing username
in this case. To avoid this problem, it should check the existence of config
or environment variables before calling ui.username().

http://selenic.com/hg/file/5db16424142c/mercurial/ui.py#l394

Alternatively, we can hack ui object to raise util.Abort appropriately,
but it seems much more complicated than this change.

Closes #2363.

  • Participants
  • Parent commits 7cad870
  • Branches stable

Comments (0)

Files changed (1)

File tortoisehg/hgqt/qtlib.py

     def sizeHint(self):
         return QSize(self.width, self.height)
 
+def _configuredusername(ui):
+    # need to check the existence before calling ui.username(); otherwise it
+    # may fall back to the system default.
+    if (not os.environ.get('HGUSER') and not ui.config('ui', 'username')
+        and not os.environ.get('EMAIL')):
+        return None
+    try:
+        return ui.username()
+    except error.Abort:
+        return None
+
 def getCurrentUsername(widget, repo, opts=None):
     if opts:
         # 1. Override has highest priority
             return user
 
     # 2. Read from repository
-    try:
-        return repo.ui.username()
-    except error.Abort:
-        pass
+    user = _configuredusername(repo.ui)
+    if user:
+        return user
 
     # 3. Get a username from the user
     QMessageBox.information(widget, _('Please enter a username'),
     dlg = SettingsDialog(False, focus='ui.username')
     dlg.exec_()
     repo.invalidateui()
-    try:
-        return repo.ui.username()
-    except error.Abort:
-        return None
+    return _configuredusername(repo.ui)
 
 class _EncodingSafeInputDialog(QInputDialog):
     def accept(self):