[PATCH 5 of 8 hglib] client: add move command

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


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1313272168 -10800
# Node ID 17d5b8e98e63dd8a482bd2ff9b56eead4e0a051d
# Parent  cfb82e8a2ab150fe633e7ae8894ddcdcdd795133
client: add move command

diff -r cfb82e8a2ab1 -r 17d5b8e98e63 hglib/client.py
--- a/hglib/client.py	Sun Aug 14 00:49:15 2011 +0300
+++ b/hglib/client.py	Sun Aug 14 00:49:28 2011 +0300
@@ -417,6 +417,27 @@
 
         return self._parserevs(out)
 
+    def move(self, source, dest, after=False, force=False, dryrun=False,
+             include=None, exclude=None):
+        if not isinstance(source, list):
+            source = [source]
+
+        source.append(dest)
+        args = cmdbuilder('move', *source, A=after, f=force, n=dryrun,
+                          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)
+
+        self.rawcommand(args, eh=eh)
+        return not warnings[0]
+
     def outgoing(self, revrange=None, path=None, force=False, newest=False,
                  bookmarks=False, branch=None, limit=None, nomerges=False,
                  subrepos=False):
diff -r cfb82e8a2ab1 -r 17d5b8e98e63 tests/test-move.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-move.py	Sun Aug 14 00:49:28 2011 +0300
@@ -0,0 +1,14 @@
+import common, os
+
+class test_move(common.basetest):
+    def test_basic(self):
+        self.append('a', 'a')
+        self.client.add('a')
+        self.assertTrue(self.client.move('a', 'b'))
+
+    # hg returns 0 even if there were warnings
+    #def test_warnings(self):
+    #    self.append('a', 'a')
+    #    self.client.add('a')
+    #    os.mkdir('c')
+    #    self.assertFalse(self.client.move(['a', 'b'], 'c'))


More information about the Mercurial-devel mailing list