changeset 30:b7042bb3dbfd

client: add remove command
author Idan Kamara <idankk86@gmail.com>
date Sun, 14 Aug 2011 00:48:51 +0300
parents c072f525ea3e
children ee8863882aae
files hglib/client.py tests/test-remove.py
diffstat 2 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hglib/client.py	Sun Aug 14 00:48:40 2011 +0300
+++ b/hglib/client.py	Sun Aug 14 00:48:51 2011 +0300
@@ -456,6 +456,24 @@
             out = self.rawcommand(args)
             return out.rstrip()
 
+    def remove(self, files, after=False, force=False, include=None, exclude=None):
+        if not isinstance(files, list):
+            files = [files]
+
+        args = cmdbuilder('remove', *files, A=after, f=force, I=include, X=exclude)
+
+        # we could use Python 3 nonlocal here...
+        warnings = [False]
+
+        def eh(ret, out, err):
+            if ret == 1:
+                warnings[0] = True
+            else:
+                raise error.CommandError(args, ret, out, err)
+
+        out = self.rawcommand(args, eh=eh)
+        return not warnings[0]
+
     def root(self):
         return self.rawcommand(['root']).rstrip()
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-remove.py	Sun Aug 14 00:48:51 2011 +0300
@@ -0,0 +1,12 @@
+import common
+
+class test_remove(common.basetest):
+    def test_basic(self):
+        self.append('a', 'a')
+        self.client.commit('first', addremove=True)
+        self.assertTrue(self.client.remove(['a']))
+
+    def test_warnings(self):
+        self.append('a', 'a')
+        self.client.commit('first', addremove=True)
+        self.assertFalse(self.client.remove(['a', 'b']))