Henrik Stuart avatar Henrik Stuart committed 728b8f7

add --remove to branchalias

Comments (0)

Files changed (1)

hg-renamebranch.py

     def add(self, branch, alias):
         self.aliases[branch] = alias
 
+    def remove(self, branch):
+        del self.aliases[branch]
+
     def write(self):
         data = ''.join(['%d %d %s %s\n' % (len(x), len(y), x, y)
             for x, y in self.aliases.iteritems()])
     def __bool__(self):
         return len(self.aliases) != 0
 
+    def __contains__(self, key):
+        return self.aliases.__contains__(key)
+
 
 def _branch(orig, self):
     retval = orig(self)
             ui.status('  %s -> %s\n' % (src, tgt))
         return
 
+    if opts.get('remove'):
+        if len(args) != 1:
+            raise util.Abort('specify a branch to remove')
+
+        if args[0] not in repo.branchalias:
+            raise util.Abort('unknown branch alias')
+
+        lock = repo.lock()
+        try:
+            repo.branchalias.remove(args[0])
+            repo.branchalias.write()
+            repo.invalidatecaches()
+        finally:
+            lock.release()
+
+        return
+
     if len(args) != 2:
         raise util.Abort('specify both branch source and target')
 
 
 cmdtable = {
         'branchalias|balias': (_branchalias,
-            [('l', 'list', False, 'show branch aliases')],
-            'BRANCHNAME BRANCHALIAS'),
+            [
+                ('l', 'list', False, 'show branch aliases'),
+                ('', 'remove', False, 'remove branch alias'),
+            ],
+            '[-l] [--remove BRANCHNAME] [BRANCHNAME] [BRANCHALIAS]'),
         }
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.