sapling/eden/scm/tests/test-fb-hgext-checkmessagehook-t.py
Jun Wu dabb68c1e5 checkmessagehook: make error message more obvious
Summary: This hopefully makes it more obvious so it looks less like an hg crash.

Reviewed By: kulshrax

Differential Revision: D23509569

fbshipit-source-id: 7174780bc7e9841e3f89a482280c49427b62fb74
2020-09-04 14:55:14 -07:00

42 lines
1.4 KiB
Python

# Copyright (c) Facebook, Inc. and its affiliates.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
from testutil.dott import sh, testtmp # noqa: F401
sh % "cat" << r"""
[extensions]
checkmessagehook=
""" >> "$HGRCPATH"
# Build up a repo
sh % "hg init repo" == ""
sh % "cd repo"
sh % "touch a"
sh % 'hg commit -A -l "$TESTDIR/ctrlchar-msg.txt"' == r"""
adding a
+-------------------------------------------------------------
| Non-printable characters in commit message are not allowed.
| Edit your commit message to fix this issue.
| The problematic commit message can be found at:
| Line 5: 'This has a sneaky ctrl-A: \x01'
| Line 6: 'And this has esc: \x1b'
+-------------------------------------------------------------
abort: pretxncommit.checkmessage hook failed
[255]"""
sh % 'hg commit -A -l "$TESTDIR/perfectlyok-msg.txt"' == "adding a"
sh % "hg log -r ." == r"""
commit: d9cf9881be7b
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: This commit message is perfectly OK, and has no sneaky control characters."""
# Try force adding a non-printable character
sh % "touch b"
sh % 'hg commit -A -l "$TESTDIR/ctrlchar-msg.txt" --config checkmessage.allownonprintable=True' == "adding b"