Hook to prevent pushes to keys conflicting with repo names
authorGregory Szorc <gps@mozilla.com>
Wed, 16 Oct 2013 15:54:56 -0700
changeset 48 373b4c93db0fe569d5544367b915f247d1e05e37
parent 47 b33779100773eb3bf05347c677c182098cc46e11
child 49 62f51eeea26b0b4cbd301ee8e19fe90ea872521a
push id31
push usergszorc@mozilla.com
push dateWed, 16 Oct 2013 22:55:02 +0000
Hook to prevent pushes to keys conflicting with repo names
__init__.py
--- a/__init__.py
+++ b/__init__.py
@@ -493,16 +493,30 @@ def buginfo(ui, repo, *bugs, **opts):
         ui.write('\n')
 
 
 def critic_hook(ui, repo, node=None, **opts):
     critique(ui, repo, node=node, **opts)
     return 0
 
 
+def reject_repo_names_hook(ui, repo, namespace=None, key=None, old=None,
+        new=None):
+    """prepushkey hook that prevents changes to reserved names.
+
+    Names that begin with the name of a repository identifier are rejected.
+    """
+    if key.lower().startswith(REPOS.keys()):
+        ui.warn('You are not allowed to push tags or bookmarks that share '
+            'names with official Mozilla repositories: %s' % key)
+        return True
+
+    return False
+
+
 def pullexpand(orig, ui, repo, source='default', **opts):
     """Wraps built-in pull command to expand aliases to multiple sources."""
     for tree, uri in resolve_trees_to_uris([source]):
         result = orig(ui, repo, uri or tree, **opts)
 
         if result:
             return result
 
@@ -744,8 +758,12 @@ def reposetup(ui, repo):
 
         def _bugs_in_description(self, desc):
             return [int(m[1]) for m in self.BUG_RE.findall(desc)]
 
     repo.__class__ = remotestrackingrepo
     if not ui.configbool('mozext', 'noautocritic'):
         ui.setconfig('hooks', 'commit.critic', critic_hook)
         ui.setconfig('hooks', 'qrefresh.critic', critic_hook)
+
+    if ui.configbool('mozext', 'reject_pushes_with_repo_names', default=False):
+        ui.setconfig('hooks', 'prepushkey.reject_repo_names',
+            reject_repo_names_hook)