[PATCH hglib] client: add support for 'hg commit --amend'
David Douard
david.douard at logilab.fr
Thu Oct 23 09:09:47 UTC 2014
# HG changeset patch
# User David Douard <david.douard at logilab.fr>
# Date 1414054209 -7200
# Thu Oct 23 10:50:09 2014 +0200
# Node ID cf8403fdd530f8d2da3a88e9e9eb5407c9fd0de9
# Parent f6b6e16531f8e72ab0016afbd5ceff1ff0c1d3fe
client: add support for 'hg commit --amend'
diff --git a/hglib/client.py b/hglib/client.py
--- a/hglib/client.py
+++ b/hglib/client.py
@@ -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
diff --git a/tests/test-commit.py b/tests/test-commit.py
--- a/tests/test-commit.py
+++ b/tests/test-commit.py
@@ -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()))
+
More information about the Mercurial-devel
mailing list