##// END OF EJS Templates
cmdutil: add special string that ignores rest of text...
Sean Farley -
r30703:5c85c93c default
parent child Browse files
Show More
@@ -49,6 +49,10 b' from . import ('
49 )
49 )
50 stringio = util.stringio
50 stringio = util.stringio
51
51
52 # special string such that everything below this line will be ingored in the
53 # editor text
54 _linebelow = "^HG: ------------------------ >8 ------------------------$"
55
52 def ishunk(x):
56 def ishunk(x):
53 hunkclasses = (crecordmod.uihunk, patch.recordhunk)
57 hunkclasses = (crecordmod.uihunk, patch.recordhunk)
54 return isinstance(x, hunkclasses)
58 return isinstance(x, hunkclasses)
@@ -2767,6 +2771,13 b' def commitforceeditor(repo, ctx, subs, f'
2767
2771
2768 editortext = repo.ui.edit(committext, ctx.user(), ctx.extra(),
2772 editortext = repo.ui.edit(committext, ctx.user(), ctx.extra(),
2769 editform=editform, pending=pending)
2773 editform=editform, pending=pending)
2774
2775 # strip away anything below this special string (used for editors that want
2776 # to display the diff)
2777 stripbelow = re.search(_linebelow, editortext, flags=re.MULTILINE)
2778 if stripbelow:
2779 editortext = editortext[:stripbelow.start()]
2780
2770 text = re.sub("(?m)^HG:.*(\n|$)", "", editortext)
2781 text = re.sub("(?m)^HG:.*(\n|$)", "", editortext)
2771 os.chdir(olddir)
2782 os.chdir(olddir)
2772
2783
@@ -689,4 +689,97 b' verify pathauditor blocks evil filepaths'
689 $ HGEDITOR="sh $TESTTMP/notouching.sh" hg commit
689 $ HGEDITOR="sh $TESTTMP/notouching.sh" hg commit
690 abort: commit message unchanged
690 abort: commit message unchanged
691 [255]
691 [255]
692
693 test that text below the --- >8 --- special string is ignored
694
695 $ hg init ignore_below_special_string
696 $ cd ignore_below_special_string
697 $ echo foo > foo
698 $ hg add foo
699 $ hg commit -m "foo"
700 $ cat >> .hg/hgrc <<EOF
701 > [committemplate]
702 > changeset.commit = first line
703 > HG: this is customized commit template
704 > HG: {extramsg}
705 > HG: ------------------------ >8 ------------------------
706 > {diff()}
707 > EOF
708 $ echo foo2 > foo2
709 $ hg add foo2
710 $ HGEDITOR=cat hg ci
711 first line
712 HG: this is customized commit template
713 HG: Leave message empty to abort commit.
714 HG: ------------------------ >8 ------------------------
715 diff -r e63c23eaa88a foo2
716 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
717 +++ b/foo2 Thu Jan 01 00:00:00 1970 +0000
718 @@ -0,0 +1,1 @@
719 +foo2
720 $ hg log -T '{desc}\n' -r .
721 first line
722
723 test that the special string --- >8 --- isn't used when not at the beginning of
724 a line
725
726 $ cat >> .hg/hgrc <<EOF
727 > [committemplate]
728 > changeset.commit = first line2
729 > another line HG: ------------------------ >8 ------------------------
730 > HG: this is customized commit template
731 > HG: {extramsg}
732 > HG: ------------------------ >8 ------------------------
733 > {diff()}
734 > EOF
735 $ echo foo >> foo
736 $ HGEDITOR=cat hg ci
737 first line2
738 another line HG: ------------------------ >8 ------------------------
739 HG: this is customized commit template
740 HG: Leave message empty to abort commit.
741 HG: ------------------------ >8 ------------------------
742 diff -r 3661b22b0702 foo
743 --- a/foo Thu Jan 01 00:00:00 1970 +0000
744 +++ b/foo Thu Jan 01 00:00:00 1970 +0000
745 @@ -1,1 +1,2 @@
746 foo
747 +foo
748 $ hg log -T '{desc}\n' -r .
749 first line2
750 another line HG: ------------------------ >8 ------------------------
751
752 also test that this special string isn't accepted when there is some extra text
753 at the end
754
755 $ cat >> .hg/hgrc <<EOF
756 > [committemplate]
757 > changeset.commit = first line3
758 > HG: ------------------------ >8 ------------------------foobar
759 > second line
760 > HG: this is customized commit template
761 > HG: {extramsg}
762 > HG: ------------------------ >8 ------------------------
763 > {diff()}
764 > EOF
765 $ echo foo >> foo
766 $ HGEDITOR=cat hg ci
767 first line3
768 HG: ------------------------ >8 ------------------------foobar
769 second line
770 HG: this is customized commit template
771 HG: Leave message empty to abort commit.
772 HG: ------------------------ >8 ------------------------
773 diff -r ce648f5f066f foo
774 --- a/foo Thu Jan 01 00:00:00 1970 +0000
775 +++ b/foo Thu Jan 01 00:00:00 1970 +0000
776 @@ -1,2 +1,3 @@
777 foo
778 foo
779 +foo
780 $ hg log -T '{desc}\n' -r .
781 first line3
782 second line
783
692 $ cd ..
784 $ cd ..
785
General Comments 0
You need to be logged in to leave comments. Login now