# HG changeset patch # User David Douard # Date 1414054209 -7200 # Node ID dc63978871ed870dcab3d181e1856931a4d2cf9b # Parent f6b6e16531f8e72ab0016afbd5ceff1ff0c1d3fe client: add support for 'hg commit --amend' diff -r f6b6e16531f8 -r dc63978871ed hglib/client.py --- 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 diff -r f6b6e16531f8 -r dc63978871ed tests/test-commit.py --- 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())) +