changeset 3119:cc740c545776

topicmode: add new warning topicmode
author Boris Feld <boris.feld@octobus.net>
date Sat, 30 Sep 2017 23:00:21 +0100
parents 255e66783505
children 89855920fb0f
files hgext3rd/topic/__init__.py tests/test-topic.t tests/test-topicmode.t
diffstat 3 files changed, 73 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py
+++ b/hgext3rd/topic/__init__.py
@@ -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):
--- a/tests/test-topic.t
+++ b/tests/test-topic.t
@@ -943,6 +943,7 @@
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     added a
   
+
 Testing the --age flag for `hg topics`
 ======================================
 
new file mode 100644
--- /dev/null
+++ b/tests/test-topicmode.t
@@ -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 <<EOF >> .hg/hgrc
+  > [phases]
+  > publish=false
+  > EOF
+  $ cat <<EOF >> $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 <<EOF >> .hg/hgrc
+  > [phases]
+  > publish=false
+  > EOF
+  $ cat <<EOF >> $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'
+