diff hglib/client.py @ 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 1b47146a4a2c
children fe74d5599539
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