changeset 57:2657fd6fef04

client: add heads command
author Idan Kamara <idankk86@gmail.com>
date Fri, 19 Aug 2011 20:08:13 +0300
parents 9bd819da245a
children 3d413c54e048
files hglib/client.py tests/test-heads.py
diffstat 2 files changed, 34 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hglib/client.py	Fri Aug 19 20:08:13 2011 +0300
+++ b/hglib/client.py	Fri Aug 19 20:08:13 2011 +0300
@@ -434,6 +434,24 @@
 
         return util.grouper(fieldcount, out)
 
+    def heads(self, rev=[], startrev=[], topological=False, closed=False):
+        """
+        Return a list of current repository heads or branch heads
+        """
+        if not isinstance(rev, list):
+            rev = [rev]
+
+        args = cmdbuilder('heads', *rev, r=startrev, t=topological, c=closed,
+                          template=templates.changeset)
+
+        def eh(ret, out, err):
+            if ret != 1:
+                raise error.CommandError(args, ret, out, err)
+            return ''
+
+        out = self.rawcommand(args, eh=eh).split('\0')[:-1]
+        return self._parserevs(out)
+
     def diff(self, files=[], revs=[], change=None, text=False,
              git=False, nodates=False, showfunction=False, reverse=False,
              ignoreallspace=False, ignorespacechange=False, ignoreblanklines=False,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-heads.py	Fri Aug 19 20:08:13 2011 +0300
@@ -0,0 +1,16 @@
+import common
+
+class test_heads(common.basetest):
+    def test_empty(self):
+        self.assertEquals(self.client.heads(), [])
+
+    def test_basic(self):
+        self.append('a', 'a')
+        rev, node0 = self.client.commit('first', addremove=True)
+        self.assertEquals(self.client.heads(), [self.client.tip()])
+
+        self.client.branch('foo')
+        self.append('a', 'a')
+        rev, node1 = self.client.commit('second')
+
+        self.assertEquals(self.client.heads(node0, topological=True), [])