# HG changeset patch # User Tony Tung # Date 1444452294 25200 # Node ID bec1a579ebc4af13af39bc6c5e15d295c71fc883 # Parent e1568d5eb0522b3ab20a1cbb15ec06f6d198c9a8 commit: abort when a committemplate is not changed If a committemplate is provided and no message is provided on the command line, and no edits are made to the commit template, then abort the commit. diff -r e1568d5eb052 -r bec1a579ebc4 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Wed Oct 14 16:04:43 2015 -0700 +++ b/mercurial/cmdutil.py Fri Oct 09 21:44:54 2015 -0700 @@ -2691,19 +2691,22 @@ def commiteditor(repo, ctx, subs, editform=''): if ctx.description(): return ctx.description() - return commitforceeditor(repo, ctx, subs, editform=editform) + return commitforceeditor(repo, ctx, subs, editform=editform, + unchangedmessagedetection=True) def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None, - editform=''): + editform='', unchangedmessagedetection=False): if not extramsg: extramsg = _("Leave message empty to abort commit.") forms = [e for e in editform.split('.') if e] forms.insert(0, 'changeset') + templatetext = None while forms: tmpl = repo.ui.config('committemplate', '.'.join(forms)) if tmpl: - committext = buildcommittemplate(repo, ctx, subs, extramsg, tmpl) + templatetext = committext = buildcommittemplate( + repo, ctx, subs, extramsg, tmpl) break forms.pop() else: @@ -2712,14 +2715,18 @@ # run editor in the repository root olddir = os.getcwd() os.chdir(repo.root) - text = repo.ui.edit(committext, ctx.user(), ctx.extra(), editform=editform) - text = re.sub("(?m)^HG:.*(\n|$)", "", text) + editortext = repo.ui.edit(committext, ctx.user(), ctx.extra(), + editform=editform) + + text = re.sub("(?m)^HG:.*(\n|$)", "", editortext) os.chdir(olddir) if finishdesc: text = finishdesc(text) if not text.strip(): raise error.Abort(_("empty commit message")) + if unchangedmessagedetection and editortext == templatetext: + raise error.Abort(_("commit message unchanged")) return text diff -r e1568d5eb052 -r bec1a579ebc4 tests/test-commit.t --- a/tests/test-commit.t Wed Oct 14 16:04:43 2015 -0700 +++ b/tests/test-commit.t Fri Oct 09 21:44:54 2015 -0700 @@ -650,3 +650,30 @@ $ hg co --clean tip abort: path contains illegal component: HG8B6C~2/hgrc (glob) [255] + +# test that an unmodified commit template message aborts + + $ hg init unmodified_commit_template + $ cd unmodified_commit_template + $ echo foo > foo + $ hg add foo + $ hg commit -m "foo" + $ cat >> .hg/hgrc < [committemplate] + > changeset.commit = HI THIS IS NOT STRIPPED + > HG: this is customized commit template + > HG: {extramsg} + > {if(activebookmark, + > "HG: bookmark '{activebookmark}' is activated\n", + > "HG: no bookmark is activated\n")}{subrepos % + > "HG: subrepo '{subrepo}' is changed\n"} + > EOF + $ cat > $TESTTMP/notouching.sh < true + > EOF + $ echo foo2 > foo2 + $ hg add foo2 + $ HGEDITOR="sh $TESTTMP/notouching.sh" hg commit + abort: commit message unchanged + [255] + $ cd ..