changeset 1858:4ab1b854ce4e

topics: allow commits that only change topic (issue4725) This allows amend to change topics. It also matches the behavior of branches.
author Matt Mackall <mpm@selenic.com>
date Mon, 15 Jun 2015 17:29:07 -0500
parents a506ed8ab8da
children fdfa611b8ab0
files src/topic/__init__.py tests/test-topic.t
diffstat 2 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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
@@ -44,6 +44,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
--- 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
+  |