diff hglib/client.py @ 20:6a9d16ddae31

client: add update command
author Idan Kamara <idankk86@gmail.com>
date Thu, 11 Aug 2011 15:42:59 +0300
parents 518149e32888
children ffef7df076e8
line wrap: on
line diff
--- a/hglib/client.py	Thu Aug 11 15:42:58 2011 +0300
+++ b/hglib/client.py	Thu Aug 11 15:42:59 2011 +0300
@@ -341,3 +341,29 @@
 
         return self._parserevs(out)[0]
 
+    def update(self, rev=None, clean=False, check=False, date=None):
+        """
+        Update the repository's working directory to changeset specified by rev.
+        If rev isn't specified, update to the tip of the current named branch.
+
+        Return the number of files (updated, merged, removed, unresolved)
+        """
+        if clean and check:
+            raise ValueError('clean and check cannot both be True')
+
+        args = cmdbuilder('update', r=rev, C=clean, c=check, d=date)
+
+        def eh(ret, out, err):
+            if ret == 1:
+                return out
+
+            raise error.CommandError(args, ret, out, err)
+
+
+        out = self.rawcommand(args, eh=eh)
+
+        # filter out 'merging ...' lines
+        out = util.skiplines(out, 'merging ')
+
+        counters = out.rstrip().split(', ')
+        return tuple(int(s.split(' ', 1)[0]) for s in counters)