Angel Ezquerra  committed 8c32919

commit: prompt the user to set a default username on commit if necessary

Currently TortoiseHg does not ever prompt the user to set its default username.
This means that is quite easy to make a commit with an undesired username. This
is particularly true on Windows, where the default username is the current
account name followed by "@" and the full network computer name.

With this change TortoiseHg checks whether a default username is set, and if not
it prompts the user to set one (letting the user open the settings dialog right
from the prompt).

  • Participants
  • Parent commits 0472f43

Comments (2)

  1. Josip Medved

    If there is an username available for given repository (e.g. username is specified in repository or username is specified in environment variable) and default username will not be used anyhow there is no reason to force user to define it at that moment. With this code user is prevented from committing code whenever default username configuration is empty...

Files changed (1)

File tortoisehg/hgqt/

     def commit(self, amend=False):
         repo = self.repo
+        defaultusername = ui.ui().config('ui', 'username')
+        if not defaultusername:
+            res = qtlib.CustomPrompt(
+                _('Default username is not configured'),
+                _('A default username is not configured. ') +
+                _('This username is used when you commit '
+                  'unless you set a different username on a given repository.\n\n') +
+                _('You must configure a default username before being able to commit.\n\n') +
+                _('Do you want to configure your default username now?'), self,
+                (_('&Configure'), _('Cancel')), 0, 1, []).run()
+            if res == 0:
+                from tortoisehg.hgqt import settings
+                settings.SettingsDialog(parent=self, focus='ui.username').exec_()
+            return
             msg = self.getMessage(False)
         except UnicodeEncodeError: