changeset 2733:adfbb984ebbb

topics: check for topic on commit before a user enters message We have a enforce-topic cofig which can forbid user to commit without a topic on it. We used to check topic on a commit after the user enters message, but we should fail early.
author Pulkit Goyal <7895pulkit@gmail.com>
date Fri, 14 Jul 2017 00:54:48 +0530
parents 4b5caa509df8
children 39c3b2b5deb0
files hgext3rd/topic/__init__.py tests/test-topic.t
diffstat 2 files changed, 13 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py	Fri Jul 14 03:14:27 2017 +0200
+++ b/hgext3rd/topic/__init__.py	Fri Jul 14 00:54:48 2017 +0530
@@ -235,11 +235,6 @@
                 current = self.currenttopic
                 if current:
                     ctx.extra()[constants.extrakey] = current
-                else:
-                    if ui.configbool('experimental', 'enforce-topic', False):
-                        # calling a function to raise an error as error variable
-                        # in this function does not refer to the error module
-                        panicforuntopicedcommit()
             if (isinstance(ctx, context.memctx) and
                 ctx.extra().get('amend_source') and
                 ctx.topic() and
@@ -576,12 +571,6 @@
 
     return topicstime
 
-def panicforuntopicedcommit():
-    msg = _("no active topic")
-    hint = _("set a current topic or use '--config " +
-             "experimental.enforce-topic=no' to commit without a topic")
-    raise error.Abort(msg, hint=hint)
-
 def summaryhook(ui, repo):
     t = repo.currenttopic
     if not t:
@@ -591,10 +580,16 @@
 
 def commitwrap(orig, ui, repo, *args, **opts):
     with repo.wlock():
+        enforcetopic = ui.configbool('experimental', 'enforce-topic')
         if opts.get('topic'):
             t = opts['topic']
             with repo.vfs.open('topic', 'w') as f:
                 f.write(t)
+        elif not repo.currenttopic and enforcetopic:
+            msg = _("no active topic")
+            hint = _("set a current topic or use '--config " +
+                     "experimental.enforce-topic=no' to commit without a topic")
+            raise error.Abort(msg, hint=hint)
         return orig(ui, repo, *args, **opts)
 
 def committextwrap(orig, repo, ctx, subs, extramsg):
--- a/tests/test-topic.t	Fri Jul 14 03:14:27 2017 +0200
+++ b/tests/test-topic.t	Fri Jul 14 00:54:48 2017 +0530
@@ -849,6 +849,13 @@
   abort: no active topic
   (set a current topic or use '--config experimental.enforce-topic=no' to commit without a topic)
   [255]
+
+(same test, checking we abort before the editor)
+
+  $ EDITOR=cat hg ci -m "Added a" --edit
+  abort: no active topic
+  (set a current topic or use '--config experimental.enforce-topic=no' to commit without a topic)
+  [255]
   $ hg ci -m "added a" --config experimental.enforce-topic=no
   $ hg log
   changeset:   0:a154386e50d1