changeset 2718:b6fa7b3e13d4

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
author Pulkit Goyal <7895pulkit@gmail.com>
date Thu, 06 Jul 2017 03:31:11 +0530
parents ed45a5fb4452
children 5191d454a4f5
files hgext3rd/topic/__init__.py tests/test-topic.t
diffstat 2 files changed, 42 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 ..