topics: add a config knob to forbid untopiced commit
authorPulkit Goyal <7895pulkit@gmail.com>
Thu, 06 Jul 2017 03:31:11 +0530
changeset 2718 b6fa7b3e13d4
parent 2717 ed45a5fb4452
child 2719 5191d454a4f5
topics: add a config knob to forbid untopiced commit After this patch one can add the following to their hgrc to stop allowing new commits with no topic on it. [experimental] enforce-topic = yes
hgext3rd/topic/__init__.py
tests/test-topic.t
--- a/hgext3rd/topic/__init__.py	Thu Jul 06 03:56:36 2017 +0530
+++ b/hgext3rd/topic/__init__.py	Thu Jul 06 03:31:11 2017 +0530
@@ -232,6 +232,11 @@
                 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
@@ -489,6 +494,12 @@
         fm.plain('\n')
     fm.end()
 
+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:
--- a/tests/test-topic.t	Thu Jul 06 03:56:36 2017 +0530
+++ b/tests/test-topic.t	Thu Jul 06 03:31:11 2017 +0530
@@ -820,3 +820,34 @@
   t2: gamma
   t1: start on fran
   t0^ Add file delta (base)
+
+  $ cd ..
+
+Testing the new config knob to forbid untopiced commit
+======================================================
+
+  $ hg init ponky
+  $ cd ponky
+  $ cat <<EOF >> .hg/hgrc
+  > [phases]
+  > publish=false
+  > EOF
+  $ cat <<EOF >> $HGRCPATH
+  > [experimental]
+  > enforce-topic = yes
+  > EOF
+  $ touch a b c d
+  $ hg add a
+  $ hg ci -m "Added a"
+  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
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     added a
+  
+  $ cd ..