##// END OF EJS Templates
commit: abort when a committemplate is not changed...
Tony Tung -
r26742:bec1a579 default
parent child Browse files
Show More
@@ -2691,19 +2691,22 b' def amend(ui, repo, commitfunc, old, ext'
2691 def commiteditor(repo, ctx, subs, editform=''):
2691 def commiteditor(repo, ctx, subs, editform=''):
2692 if ctx.description():
2692 if ctx.description():
2693 return ctx.description()
2693 return ctx.description()
2694 return commitforceeditor(repo, ctx, subs, editform=editform)
2694 return commitforceeditor(repo, ctx, subs, editform=editform,
2695 unchangedmessagedetection=True)
2695
2696
2696 def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None,
2697 def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None,
2697 editform=''):
2698 editform='', unchangedmessagedetection=False):
2698 if not extramsg:
2699 if not extramsg:
2699 extramsg = _("Leave message empty to abort commit.")
2700 extramsg = _("Leave message empty to abort commit.")
2700
2701
2701 forms = [e for e in editform.split('.') if e]
2702 forms = [e for e in editform.split('.') if e]
2702 forms.insert(0, 'changeset')
2703 forms.insert(0, 'changeset')
2704 templatetext = None
2703 while forms:
2705 while forms:
2704 tmpl = repo.ui.config('committemplate', '.'.join(forms))
2706 tmpl = repo.ui.config('committemplate', '.'.join(forms))
2705 if tmpl:
2707 if tmpl:
2706 committext = buildcommittemplate(repo, ctx, subs, extramsg, tmpl)
2708 templatetext = committext = buildcommittemplate(
2709 repo, ctx, subs, extramsg, tmpl)
2707 break
2710 break
2708 forms.pop()
2711 forms.pop()
2709 else:
2712 else:
@@ -2712,14 +2715,18 b' def commitforceeditor(repo, ctx, subs, f'
2712 # run editor in the repository root
2715 # run editor in the repository root
2713 olddir = os.getcwd()
2716 olddir = os.getcwd()
2714 os.chdir(repo.root)
2717 os.chdir(repo.root)
2715 text = repo.ui.edit(committext, ctx.user(), ctx.extra(), editform=editform)
2718 editortext = repo.ui.edit(committext, ctx.user(), ctx.extra(),
2716 text = re.sub("(?m)^HG:.*(\n|$)", "", text)
2719 editform=editform)
2720
2721 text = re.sub("(?m)^HG:.*(\n|$)", "", editortext)
2717 os.chdir(olddir)
2722 os.chdir(olddir)
2718
2723
2719 if finishdesc:
2724 if finishdesc:
2720 text = finishdesc(text)
2725 text = finishdesc(text)
2721 if not text.strip():
2726 if not text.strip():
2722 raise error.Abort(_("empty commit message"))
2727 raise error.Abort(_("empty commit message"))
2728 if unchangedmessagedetection and editortext == templatetext:
2729 raise error.Abort(_("commit message unchanged"))
2723
2730
2724 return text
2731 return text
2725
2732
@@ -650,3 +650,30 b' verify pathauditor blocks evil filepaths'
650 $ hg co --clean tip
650 $ hg co --clean tip
651 abort: path contains illegal component: HG8B6C~2/hgrc (glob)
651 abort: path contains illegal component: HG8B6C~2/hgrc (glob)
652 [255]
652 [255]
653
654 # test that an unmodified commit template message aborts
655
656 $ hg init unmodified_commit_template
657 $ cd unmodified_commit_template
658 $ echo foo > foo
659 $ hg add foo
660 $ hg commit -m "foo"
661 $ cat >> .hg/hgrc <<EOF
662 > [committemplate]
663 > changeset.commit = HI THIS IS NOT STRIPPED
664 > HG: this is customized commit template
665 > HG: {extramsg}
666 > {if(activebookmark,
667 > "HG: bookmark '{activebookmark}' is activated\n",
668 > "HG: no bookmark is activated\n")}{subrepos %
669 > "HG: subrepo '{subrepo}' is changed\n"}
670 > EOF
671 $ cat > $TESTTMP/notouching.sh <<EOF
672 > true
673 > EOF
674 $ echo foo2 > foo2
675 $ hg add foo2
676 $ HGEDITOR="sh $TESTTMP/notouching.sh" hg commit
677 abort: commit message unchanged
678 [255]
679 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now