Angel Ezquerra avatar Angel Ezquerra committed 4edf7bf

incoming: prompt user to update projrc file on incoming

Up until now the user would only see a message saying that there is an updated
projrc file when running hg incoming, but it would need to run hg pull to
be able to update the projrc file.

This patch changes the default behavior so that the user will be prompted to
update the projrc file if the remote and local copies differ.

It is also possible to change the default behavior so that you only get a change
notification (without update prompt) or so that incoming respects the
projrc.confirm setting.

Comments (0)

Files changed (2)

 * ``projrc.servers``: Servers to Pull From
 * ``projrc.include``: Included Sections
 * ``projrc.exclude``: Excluded Sections
-* ``projrc.comfirm``: Confirmation Settings
+* ``projrc.confirm``: Confirmation Settings
+* ``projrc.updateonincoming``: Confirmation Settings for incoming command
 
 These are explained in the following sections.
 
 Confirmation Settings
 ---------------------
 
+There are two settings that control how and if the user must
+confirm updates to the local projrc file:
+
+1. ``confirm``:
+
 The ``projrc.confirm`` configuration key controls whether the user
 must confirm the transfer of new projr settings.
 
 (i.e. the extension does not remember your previous answer to the
 confirmation prompt).
 
+2. ``updateonincoming``:
+
+The ``projrc.updateonincoming`` configuration key controls whether
+the user gets a prompt to update the projrc file when it runs the
+incoming mercurial command.
+
+Valid values for the ``projrc.updateonincoming`` configuration key are:
+
+:``never`` / ``False``: Show whether the remote projrc file has changed, 
+                        but do not upate (nor ask to update) the local
+                        projrc file.
+
+:``prompt``: Look for changes to the projrc file.
+          If there are changes _always_ show a confirmation prompt,
+          asking the user if it wants to update its local projrc file.
+
+:``auto``: Look for changes to the projrc file.
+          Use the value of the 'projrc.confirm' configuration key to
+          determine whether to show a confirmation dialog or not
+          before updating the local projrc file.
+
+Note that if the field is set but empty the extension will behave as
+if it was set to 'prompt'. That is::
+
+  [projrc]
+  incoming =
+
+is equivalent to::
+
+  [projrc]
+  incoming = prompt
+
 
 Configuration Examples
 ----------------------
    This is a safer variation of the previous configuration. The
    difference is that the user will get a confirmation prompt whenever
    the projrc file changes.
+   
+   You can also configure the incoming command to prompt for changes
+   by adding::
+
+     updateonincoming = prompt
 
 5. Accept all project configurations from a central repo and from
    local repositories, but prompt the first time that a projrc file is
                 valid = False
     return data, valid
 
-def transferprojrc(ui, repo, other):
+def transferprojrc(ui, repo, other, confirmupdate=None):
     data, valid = getremoteprojrc(ui, repo, other)
     if not valid or data is None:
         return
                         return False
                     return True
 
-                confirmchanges = mustconfirm(olddata != "")
+                if confirmupdate is None:
+                    confirmupdate = mustconfirm(olddata != "")
                 acceptnewconfig = True
-                if confirmchanges:
+                if confirmupdate:
                     action = ui.promptchoice(
                         _("The project settings file (projrc) has changed.\n"
                         "Do you want to update it? (y/n)"),
 
 def incoming(orig, ui, repo, srcpath, *args, **kwargs):
     """
-    execute the regular hg.incoming, and then show
-    whether the remote and local projrc files are different.
+    execute the regular hg.incoming, and then read
+    the projrc.updateonincoming setting. Depending on its
+    value the behavior will be different:
+    
+    - false / never: Show whether the remote projrc file
+          has changed, but do not upate (nor ask to update)
+          the local projrc file.
+          This is the default.
+    - prompt: Look for changes to the projrc file.
+          If there are changes _always_ show a confirmation
+          prompt, asking the user if it wants to update its
+          local projrc file.
+    - auto: Look for changes to the projrc file.
+          Use the value of the 'projrc.confirm' configuration
+          key to determine whether to show a confirmation
+          dialog or not before updating the local projrc file.
+
+    Note that if the field is set but empty the extension
+    will behave as if it was set to 'prompt'.
     """
 
     res = orig(ui, repo, srcpath, *args, **kwargs)
 
-    olddata = readcurrentprojrc(repo)
-    if olddata:
-        ui.note(_('searching for changes to the projrc file\n'))
-    else:
-        ui.note(_('looking for remote projrc file\n'))
-
     expandedpath = ui.expandpath(srcpath)
     other = hg.repository(ui, expandedpath)
-    data, valid = getremoteprojrc(ui, repo, other)
-    if valid:
-        # If not valid we will already have shown a warning message
+
+    def mustupdateonincoming():
+        default = 'false'
+        updateonincoming = ui.config('projrc', 'updateonincoming',
+            default=default)
+        if (updateonincoming == ''):
+            # prompt for confirmation when the field is set but empty
+            # The reason is that it is reasonable for a user to expect
+            # to be ableto update the projrc file when it sets
+            # a field called 'updateonincoming'
+            return 'prompt'
+        if util.parsebool(updateonincoming) == False:
+            # we don't want to get here when None!
+            return 'false'
+        updateonincoming = updateonincoming.lower()
+        if not updateonincoming in ('auto', 'prompt'):
+             ui.warn(_('invalid projrc.updateonincoming value (%s).\n'
+                'using default projrc.updateonincoming value instead '
+                '(%s)\n' % (updateonincoming, default)))
+             return default
+        return updateonincoming
+
+    updateonincoming = mustupdateonincoming()
+    if updateonincoming == 'false':
+        # Show whether the projrc file has changed, but do not
+        # update nor prompt the user to update the local projrc file
+        olddata = readcurrentprojrc(repo)
         if olddata:
-            if olddata != data:
-                ui.status(_('remote and local projrc files are different\n'))
-            else:
-                ui.note(_('no changes found to projrc file\n'))
-        elif data:
-            ui.status(_('new remote projrc file found\n'))
+            ui.note(_('searching for changes to the projrc file\n'))
+        else:
+            ui.note(_('looking for remote projrc file\n'))
+
+        data, valid = getremoteprojrc(ui, repo, other)
+        if valid:
+            # If not valid we will already have shown a warning message
+            if olddata:
+                if olddata != data:
+                    ui.status(_('remote and local projrc files are different\n'))
+                else:
+                    ui.note(_('no changes found to projrc file\n'))
+            elif data:
+                ui.status(_('new remote projrc file found\n'))
+    else:
+        confirmupdate = True
+        if updateonincoming == 'auto':
+            confirmupdate = None
+        transferprojrc(ui, repo, other, confirmupdate=confirmupdate)
 
     return res
 
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.