[PATCH topic-ext] topics: allow commits that only change topic (issue4725)

Matt Mackall mpm at selenic.com
Mon Jun 15 22:30:49 UTC 2015


# HG changeset patch
# User Matt Mackall <mpm at selenic.com>
# Date 1434407347 18000
#      Mon Jun 15 17:29:07 2015 -0500
# Node ID d038b92c51d91c99b50fd17c829e22212de051bb
# Parent  ca2b4e5329fe018fc1279694cc89f74a7d6f4ccd
topics: allow commits that only change topic (issue4725)

This allows amend to change topics. It also matches the behavior of branches.

diff -r ca2b4e5329fe -r d038b92c51d9 src/topic/__init__.py
--- a/src/topic/__init__.py	Mon Jun 15 16:56:44 2015 -0500
+++ b/src/topic/__init__.py	Mon Jun 15 17:29:07 2015 -0500
@@ -43,6 +43,16 @@
 def reposetup(ui, repo):
     orig = repo.__class__
     class topicrepo(repo.__class__):
+        def commit(self, *args, **kwargs):
+            backup = self.ui.backupconfig('ui', 'allowemptycommit')
+            try:
+                if repo.currenttopic != repo['.'].extra().get('topic'):
+                    # bypass the core "nothing changed" logic
+                    self.ui.setconfig('ui', 'allowemptycommit', True)
+                return orig.commit(self, *args, **kwargs)
+            finally:
+                self.ui.restoreconfig(backup)
+
         def commitctx(self, ctx, error=None):
             if isinstance(ctx, context.workingcommitctx):
                 current = self.currenttopic
diff -r ca2b4e5329fe -r d038b92c51d9 tests/test-topic.t
--- a/tests/test-topic.t	Mon Jun 15 16:56:44 2015 -0500
+++ b/tests/test-topic.t	Mon Jun 15 17:29:07 2015 -0500
@@ -550,3 +550,24 @@
   |  date:        Thu Jan 01 00:00:00 1970 +0000
   |  summary:     start on fran
   |
+
+Amend a topic
+
+  $ hg topic watwat
+  $ hg ci --amend
+  $ hg log -Gr 'draft()'
+  @  changeset:   16:893ffcf66c1f
+  |  tag:         tip
+  |  topic:       watwat
+  |  parent:      13:d91cd8fd490e
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     fran?
+  |
+  o  changeset:   13:d91cd8fd490e
+  |  topic:       wat
+  |  parent:      3:a53952faf762
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     start on fran
+  |


More information about the Mercurial-devel mailing list