[PATCH 3 of 8 hglib] client: add remove command

Idan Kamara idankk86 at gmail.com
Sat Aug 13 16:58:34 CDT 2011


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1313272131 -10800
# Node ID eca507c161dd515ea70bad2e2837de921837f8ff
# Parent  fc12804561dad0344f9f382364afc826c837ccc7
client: add remove command

diff -r fc12804561da -r eca507c161dd hglib/client.py
--- 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()
 
diff -r fc12804561da -r eca507c161dd tests/test-remove.py
--- /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']))


More information about the Mercurial-devel mailing list