# HG changeset patch # User Boris Feld # Date 1506808821 -3600 # Node ID cc740c545776dc9c7748f4d2afe8d43ff8eb9d86 # Parent 255e66783505603f3c97850df49c15fe2494e97c topicmode: add new warning topicmode diff -r 255e66783505 -r cc740c545776 hgext3rd/topic/__init__.py --- a/hgext3rd/topic/__init__.py Sun Oct 01 00:14:19 2017 +0100 +++ b/hgext3rd/topic/__init__.py Sat Sep 30 23:00:21 2017 +0100 @@ -58,6 +58,7 @@ [experimental] # behavior when commit is made without an active topic topic-mode = ignore # do nothing special (default) + topic-mode = warning # print a warning topic-mode = enforce # abort the commit """ @@ -888,6 +889,7 @@ _validmode = [ 'ignore', + 'warning', 'enforce', ] @@ -918,6 +920,8 @@ hint = _("set a current topic or use '--config " + "experimental.topic-mode=off' to commit without a topic") raise error.Abort(msg, hint=hint) + elif not repo.currenttopic and topicmode == 'warning': + ui.warn(_("warning: new draft commit without topic\n")) return orig(ui, repo, *args, **opts) def committextwrap(orig, repo, ctx, subs, extramsg): diff -r 255e66783505 -r cc740c545776 tests/test-topic.t --- a/tests/test-topic.t Sun Oct 01 00:14:19 2017 +0100 +++ b/tests/test-topic.t Sat Sep 30 23:00:21 2017 +0100 @@ -943,6 +943,7 @@ date: Thu Jan 01 00:00:00 1970 +0000 summary: added a + Testing the --age flag for `hg topics` ====================================== diff -r 255e66783505 -r cc740c545776 tests/test-topicmode.t --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-topicmode.t Sat Sep 30 23:00:21 2017 +0100 @@ -0,0 +1,68 @@ + $ . "$TESTDIR/testlib/topic_setup.sh" + +Testing the new config knob to forbid untopiced commit +====================================================== + + $ hg init $TESTTMP/untopic-commit + $ cd $TESTTMP/untopic-commit + $ cat <> .hg/hgrc + > [phases] + > publish=false + > EOF + $ cat <> $HGRCPATH + > [experimental] + > topic-mode = enforce + > 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.topic-mode=off' 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.topic-mode=off' to commit without a topic) + [255] + $ hg ci -m "added a" --config experimental.topic-mode=off + $ hg log + changeset: 0:a154386e50d1 + tag: tip + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: added a + + +Testing the new config knob to warn about untopiced commit +========================================================== + + $ hg init $TESTTMP/untopic-warn-commit + $ cd $TESTTMP/untopic-warn-commit + $ cat <> .hg/hgrc + > [phases] + > publish=false + > EOF + $ cat <> $HGRCPATH + > [experimental] + > topic-mode = warning + > EOF + $ touch a b c d + $ hg add a + $ hg ci -m "Added a" + warning: new draft commit without topic + +(same test, checking we abort before the editor) + + $ EDITOR=cat hg ci --amend -m "Added a" --edit + warning: new draft commit without topic + $ hg ci --amend -m "added a'" --config experimental.topic-mode=off + $ hg log + changeset: 2:2e862d8b5eff + tag: tip + parent: -1:000000000000 + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: added a' +