1. Angel Ezquerra
  2. hgrcshare

Commits

Angel Ezquerra  committed 17927ed

Prompt the user to confirm before accepting any project configuration changes.
The user can set a "confirm" key to False to automatically accept all
configuration changes.

  • Participants
  • Parent commits 9a24321
  • Branches default

Comments (0)

Files changed (2)

File README

View file
 If a key matches both an include and an exclude (glob) pattern of the same
 length, the key is _included_ (i.e. inclusion takes precedence over exclusion).
 
+4. confirm:
+
+If this key is not set, the user will be asked for confirmation before
+accepting any changes to the project configuration.
+
+Set this key to "False" if you want to automatically accept all changes
+to the project configuration.
+
 
 Please send bug reports to the `Mercurial mailinglist`__.
 

File projrc.py

View file
         for order, key, value, src in items:
             cfg.set(section, key, value, src)
 
+def readcurrentprojrc(repo):
+    """Return the contents of the current projrc file"""
+    try:
+        fp = repo.opener('projrc', 'r')
+        data = fp.read()
+        fp.close()
+    except IOError:
+        data = ""
+    return data
+
 def readprojrc(ui, rpath):
     # Modelled after dispatch._getlocal but reads the projrc settings
     # directly into the ui object.
         try:
             c = config.config()
             c.parse('projrc', data)
-
             # Filter the received config, only allowing the sections that
             # the user has specified in any of its hgrc files
             data = ENCODING_CHECK + \
                 serializeconfig(c, includedkeys, excludedkeys)
 
-            fp = repo.opener('projrc', 'w')
-            fp.write(data)
-            fp.close()
+            # Compare the old projrc with the new one
+            olddata = readcurrentprojrc(repo)
+            if olddata != data:
+                confirmchanges = ui.configbool(
+                    'projrc', 'confirm', default=True)
+                if not confirmchanges:
+                    acceptnewconfig = True
+                else:
+                    action = ui.promptchoice(
+                        _("The project settings file (projrc) has changed.\n"
+                        "Do you want to update it? (yn)"),
+                        (_('&Yes'), _('&No')), default=0)
+                    acceptnewconfig = (action == 0)
+                if acceptnewconfig:
+                    # If there are changes and the user accepts them, save the new projrc
+                    fp = repo.opener('projrc', 'w')
+                    fp.write(data)
+                    fp.close()
 
-            # take any transferred settings into account
-            try:
-                loadprojrc(repo.ui, repo.join('projrc'), repo.root)
-                extensions.loadall(repo.ui)
-            except IOError:
-                pass
+                    # and take any transferred settings into account
+                    try:
+                        loadprojrc(repo.ui, repo.join('projrc'), repo.root)
+                        extensions.loadall(repo.ui)
+                    except IOError:
+                        pass
+            else:
+                print "projrc not changed"
 
         except error.ParseError, e:
             ui.warn(_("not saving retrieved projrc file: "
         if os.path.exists(repo.join('projrc')):
             os.unlink(repo.join('projrc'))
 
-
 def clone(orig, ui, *args, **kwargs):
     # hg.clone calls hg._update as the very last thing. We need to
     # transfer the .hg/projrc file before this happens in order for it