# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1499292071 -19800 # Node ID b6fa7b3e13d45463a0226814c5f81cdb632d9e5d # Parent ed45a5fb445227648a3798f12777537ebf6dfce5 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 diff -r ed45a5fb4452 -r b6fa7b3e13d4 hgext3rd/topic/__init__.py --- 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: diff -r ed45a5fb4452 -r b6fa7b3e13d4 tests/test-topic.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 <> .hg/hgrc + > [phases] + > publish=false + > EOF + $ cat <> $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 ..