Patchwork [4,of,5] client: add 'phase' method to set or get the phase of a changeset

login
register
mail settings
Submitter Paul Tonelli
Date May 22, 2014, 1:50 p.m.
Message ID <18986e5692bc00065ae1.1400766622@crater1.logilab.fr>
Download mbox | patch
Permalink /patch/4854/
State Superseded
Headers show

Comments

Paul Tonelli - May 22, 2014, 1:50 p.m.
# HG changeset patch
# User Paul Tonelli <paul.tonelli@logilab.fr>
# Date 1400257272 -7200
#      Fri May 16 18:21:12 2014 +0200
# Node ID 18986e5692bc00065ae18600f87b636d65a60df7
# Parent  e4bfec889df7bf01a694c0aaa867c84e5952181f
client: add 'phase' method to set or get the phase of a changeset

Patch

diff -r e4bfec889df7 -r 18986e5692bc hglib/client.py
--- a/hglib/client.py	Thu May 15 15:12:13 2014 +0200
+++ b/hglib/client.py	Fri May 16 18:21:12 2014 +0200
@@ -1405,6 +1405,31 @@ 
             t.append((name.rstrip(), int(rev), node, taglocal))
         return t
 
+    def phase(self, revs=(), secret=False, draft=False, public=False,
+              force=False):
+        '''Set or show the current phase name.
+
+        revs - target revision(s)
+        public - set changeset phase to public
+        draft - set changeset phase to draft
+        secret - set changeset phase to secret
+        force - allow to move boundary backward
+
+        output format: [(id, phase) ...] for each changeset
+
+        The arguments match the mercurial API.
+        '''
+        if not isinstance(revs, (list, tuple)):
+            revs = [revs]
+        args = util.cmdbuilder('phase', secret=secret, draft=draft,
+                               public=public, force=force, hidden=self.hidden, *revs)
+        out = self.rawcommand(args)
+        if draft or public or secret:
+            return
+        else:
+            output = [i.split(': ')for i in out.strip().split('\n')]
+            return [(int(num), phase) for (num, phase) in output]
+
     def summary(self, remote=False):
         """
         Return a dictionary with a brief summary of the working directory state,
diff -r e4bfec889df7 -r 18986e5692bc tests/test-phase.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-phase.py	Fri May 16 18:21:12 2014 +0200
@@ -0,0 +1,40 @@ 
+import common, hglib
+
+class test_phase(common.basetest):
+    """test the different ways to use the phase command"""
+    def test_phase(self):
+        """test getting data from a single changeset"""
+        self.append('a', 'a')
+        rev, node0 = self.client.commit('first', addremove=True)
+        self.assertEqual([(0, 'draft')], self.client.phase(node0))
+
+    def test_phase_public(self):
+        """phase change from draft to public"""
+        self.append('a', 'a')
+        rev, node0 = self.client.commit('first', addremove=True)
+        self.client.phase(node0, public=True)
+        self.assertEqual([(0, 'public')], self.client.phase(node0))
+
+    def test_phase_secret(self):
+        """phase change from draft to secret"""
+        self.append('a', 'a')
+        rev, node0 = self.client.commit('first', addremove=True)
+        with self.assertRaises(hglib.error.CommandError):
+            self.client.phase(node0, secret=True)
+        self.client.phase(node0, secret=True, force=True)
+        self.assertEqual([(0, 'secret')], self.client.phase(node0))
+
+    def test_phase_multiple(self):
+        """phase changes and show the phases of the different changesets"""
+        self.append('a', 'a')
+        rev, node0 = self.client.commit('a', addremove=True)
+        self.client.phase(node0, public=True)
+        self.append('b', 'b')
+        rev, node1 = self.client.commit('b', addremove=True)
+        self.append('c', 'c')
+        rev, node2 = self.client.commit('c', addremove=True)
+        self.client.phase(node2, secret=True, force=True)
+        self.assertEqual([(0, 'public'), (2, 'secret'), (1, 'draft')],
+                         self.client.phase([node0,node2,node1]))
+
+