changeset 136:dc63978871ed

client: add support for 'hg commit --amend'
author David Douard <david.douard@logilab.fr>
date Thu, 23 Oct 2014 10:50:09 +0200
parents f6b6e16531f8
children 7ba67c1f1f92
files hglib/client.py tests/test-commit.py
diffstat 2 files changed, 24 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hglib/client.py	Wed Oct 01 15:03:32 2014 -0500
+++ b/hglib/client.py	Thu Oct 23 10:50:09 2014 +0200
@@ -533,7 +533,7 @@
 
     def commit(self, message=None, logfile=None, addremove=False,
                closebranch=False, date=None, user=None, include=None,
-               exclude=None):
+               exclude=None, amend=False):
         """
         Commit changes reported by status into the repository.
 
@@ -545,8 +545,12 @@
         user - record the specified user as committer
         include - include names matching the given patterns
         exclude - exclude names matching the given patterns
+        amend - amend the parent of the working dir
         """
-        if message is None and logfile is None:
+        if amend and message is None and logfile is None:
+            # retrieve current commit message
+            message = self.log('.')[0][5]
+        if message is None and logfile is None and not amend:
             raise ValueError("must provide at least a message or a logfile")
         elif message and logfile:
             raise ValueError("cannot specify both a message and a logfile")
@@ -554,8 +558,7 @@
         # --debug will print the committed cset
         args = cmdbuilder('commit', debug=True, m=message, A=addremove,
                           close_branch=closebranch, d=date, u=user, l=logfile,
-                          I=include, X=exclude)
-
+                          I=include, X=exclude, amend=amend)
         out = self.rawcommand(args)
         rev, node = out.splitlines()[-1].rsplit(':')
         return int(rev.split()[-1]), node
--- a/tests/test-commit.py	Wed Oct 01 15:03:32 2014 -0500
+++ b/tests/test-commit.py	Thu Oct 23 10:50:09 2014 +0200
@@ -40,3 +40,20 @@
                                          date=now.isoformat(' '))
 
         self.assertEquals(now, self.client.tip().date)
+
+    def test_amend(self):
+        self.append('a', 'a')
+        now = datetime.datetime.now().replace(microsecond=0)
+        rev0, node0 = self.client.commit('first', addremove=True,
+                                         date=now.isoformat(' '))
+
+        print rev0, node0
+        self.assertEquals(now, self.client.tip().date)
+
+        self.append('a', 'a')
+        rev1, node1 = self.client.commit(amend=True)
+        print rev1, node1
+        self.assertEquals(now, self.client.tip().date)
+        self.assertNotEquals(node0, node1)
+        self.assertEqual(1, len(self.client.log()))
+