Commits

Fredrik Håård  committed 8f198c2

added tag support

  • Participants
  • Parent commits cfc734a

Comments (0)

Files changed (4)

  hg revert
  hg branch
  hg branches
+ hg tag
+ hg tags
 
 You also have access to the configuration (config, configbool,
 configlist) just as in the internal Mercurial API. The repository 

File hgapi/hgapi.py

         if clean: cmd.append("--clean")
         self.hg_command(*cmd)
 
+    def hg_tag(self, name, rev=None):
+        """Add a tag to the current or given revision"""
+        cmd = ['tag', name]
+        if rev: cmd += ['-r', str(rev)]
+        self.hg_command(*cmd)
+
+    def hg_tags(self):
+        """Get all tags from the repo as 
+        a dict containing tag: shortnode mapping"""
+        cmd = ['tags']
+        output = self.hg_command(*cmd)
+        res = {}
+        for row in output.strip().split('\n'):
+            tag, changeset = row.split() # tip  5:aaaaaaaaaa
+            res[tag] = changeset.split(':')[1]
+        return res
+
     def hg_heads(self):
         """Gets a list with the node id:s of all open heads"""
         res = self.hg_command("heads","--template", "{node}\n")

File hgapi/testhgapi.py

         self.assertEquals(rev.date, "2011-10-10 00:00 +0000")
         self.assertEquals(rev.parents, [rev0])
 
+    def test_210_Tags(self):
+        original_tip = self.repo['tip'].node
+        self.repo.hg_tag('mytag')
+        self.repo.hg_tag('mytag2', rev=1)
+        tags = self.repo.hg_tags()
+        self.assertEqual(tags, {'mytag': original_tip,
+            'mytag2': self.repo[1].node,
+            'tip': self.repo[-1].node})
+
+
 def test_doc():
     #Prepare for doctest
     os.mkdir("./test_hgapi")
 
 setup(
     name = "hgapi",
-    version = "1.3.0",
+    version = "1.3.1a1",
     packages = ['hgapi'],
     test_suite = "hgapi.testhgapi.TestHgAPI",
     author = "Fredrik Håård",