[PATCH hglib] client: add rebase support to client.pull (issue4644)

Axel Hecht axel at mozilla.com
Wed Apr 6 09:51:05 EDT 2016


# HG changeset patch
# User Axel Hecht <axel at pike.org>
# Date 1442331213 -7200
#      Tue Sep 15 17:33:33 2015 +0200
# Node ID 98efa416f763d5f408244baeaf6ab5e2fc4fd756
# Parent  3478adf2394ad27a4b501c91bbdae8157f06dd10
client: add rebase support to client.pull (issue4644)

Add options to pull to use --rebase. As that's supported only via the
rebase extension, make sure the extension is enable by passing in a
config option.

diff --git a/hglib/client.py b/hglib/client.py
--- a/hglib/client.py
+++ b/hglib/client.py
@@ -1187,7 +1187,7 @@
 
     def pull(self, source=None, rev=None, update=False, force=False,
              bookmark=None, branch=None, ssh=None, remotecmd=None,
-             insecure=False, tool=None):
+             insecure=False, rebase=False, tool=None):
         """Pull changes from a remote repository.
 
         This finds all changes from the repository specified by source
@@ -1207,13 +1207,19 @@
         remotecmd - specify hg command to run on the remote side
         insecure - do not verify server certificate (ignoring
          web.cacerts config)
+        rebase - rebase working directory to branch head
         tool - specify merge tool for rebase
 
         """
-        args = cmdbuilder(b('pull'), source, r=rev, u=update, f=force,
+        if rebase:
+            # make sure the rebase extension is enabled
+            config = [b('--config'), b('extensions.rebase=')]
+        else:
+            config = []
+        args = cmdbuilder(b('pull'), source, *config, r=rev, u=update, f=force,
                           B=bookmark, b=branch, e=ssh,
                           remotecmd=remotecmd, insecure=insecure,
-                          t=tool)
+                          rebase=rebase, t=tool)
 
         eh = util.reterrorhandler(args)
         self.rawcommand(args, eh=eh)
diff --git a/tests/test-pull.py b/tests/test-pull.py
--- a/tests/test-pull.py
+++ b/tests/test-pull.py
@@ -1,6 +1,7 @@
 from tests import common
 import hglib
 from hglib.util import b
+from hglib.client import revision
 
 class test_pull(common.basetest):
     def test_basic(self):
@@ -29,3 +30,25 @@
         self.append('other/a', 'b')
         self.assertFalse(other.pull(update=True))
         self.assertTrue((b('M'), b('a')) in other.status())
+
+    def test_rebase(self):
+        self.append('a', 'a')
+        self.append('b', 'b')
+        self.client.commit(b('first'), addremove=True)
+
+        self.client.clone(dest=b('other'))
+        other = hglib.open(b('other'))
+
+        self.append('a', 'a')
+        self.client.commit(b('second'))
+
+        self.append('other/b', 'b')
+        other.commit(b('third'))
+
+        self.assertTrue(other.pull(rebase=True))
+        # compare the logs, gotta trick away the 'tip' tag
+        def untip(log):
+            return [revision(*(b('') if item==b('tip') else item for item in cs)) for cs in log]
+        client_log = untip(self.client.log())
+        other_log = untip(other.log())
+        self.assertEquals(client_log, other_log[1:])


More information about the Mercurial-devel mailing list