[PATCH 3 of 3 topic-ext] commit: add a topic field to the in-editor commit text

Matt Mackall mpm at selenic.com
Fri Jun 12 15:49:54 CDT 2015


# HG changeset patch
# User Matt Mackall <mpm at selenic.com>
# Date 1433976727 18000
#      Wed Jun 10 17:52:07 2015 -0500
# Node ID d952799c8f0211c8f20a8db9d29099cac5ce2c8d
# Parent  7d7758a9bef4a197e04399aeb54115809b42ed13
commit: add a topic field to the in-editor commit text

diff -r 7d7758a9bef4 -r d952799c8f02 src/topic/__init__.py
--- a/src/topic/__init__.py	Wed Jun 10 17:40:50 2015 -0500
+++ b/src/topic/__init__.py	Wed Jun 10 17:52:07 2015 -0500
@@ -134,6 +134,14 @@
             f.write(t)
     return orig(ui, repo, *args, **opts)
 
+def committextwrap(orig, repo, ctx, subs, extramsg):
+    ret = orig(repo, ctx, subs, extramsg)
+    t = repo.currenttopic
+    if t:
+        ret = ret.replace("\nHG: branch",
+                          "\nHG: topic '%s'\nHG: branch" % t)
+    return ret
+
 def updatewrap(orig, ui, repo, *args, **kwargs):
     ret = orig(ui, repo, *args, **kwargs)
     pctx = repo['.']
@@ -155,5 +163,6 @@
                  _("use specified topic"), _('TOPIC')))
 
 extensions.wrapcommand(commands.table, 'update', updatewrap)
+extensions.wrapfunction(cmdutil, 'buildcommittext', committextwrap)
 topicrevset.modsetup()
 cmdutil.summaryhooks.add('topic', summaryhook)
diff -r 7d7758a9bef4 -r d952799c8f02 tests/test-topic.t
--- a/tests/test-topic.t	Wed Jun 10 17:40:50 2015 -0500
+++ b/tests/test-topic.t	Wed Jun 10 17:52:07 2015 -0500
@@ -42,6 +42,25 @@
 Still no topics
   $ hg topics
 
+Test commit flag and help text
+
+  $ echo stuff >> alpha
+  $ HGEDITOR=cat hg ci -t topicflag
+  
+  
+  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
+  HG: Leave message empty to abort commit.
+  HG: --
+  HG: user: test
+  HG: topic 'topicflag'
+  HG: branch 'default'
+  HG: changed alpha
+  abort: empty commit message
+  [255]
+  $ hg revert alpha
+  $ hg topic
+   * topicflag
+
 Make a topic
   $ hg topic narf
   $ hg topics


More information about the Mercurial-devel mailing list