Anonymous avatar Anonymous 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).

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)

tortoisehg/hgqt/commit.py

 
     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
+  
         try:
             msg = self.getMessage(False)
         except UnicodeEncodeError:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.