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

login
register
mail settings
Submitter Axel Hecht
Date April 6, 2016, 1:51 p.m.
Message ID <98efa416f763d5f40824.1459950665@fuchsia.local>
Download mbox | patch
Permalink /patch/14393/
State Changes Requested
Delegated to: Yuya Nishihara
Headers show

Comments

Axel Hecht - April 6, 2016, 1:51 p.m.
# HG changeset patch
# User Axel Hecht <axel@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.
Yuya Nishihara - April 8, 2016, 1:50 p.m.
On Wed, 06 Apr 2016 15:51:05 +0200, Axel Hecht wrote:
> # HG changeset patch
> # User Axel Hecht <axel@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 = []

I don't think it's the right way to support --rebase option. Extensions
shouldn't be enabled implicitly, and not all extensions could be enabled
in that way.

> +        args = cmdbuilder(b('pull'), source, *config, r=rev, u=update, f=force,

Better to write config=['extensions.rebase='] ?

*args should be positional arguments, but cmdbuilder() doesn't insert '--'
before positional arguments, which seems like a bug.

Patch

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:])