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
This commit is contained in:
Jun Wu 2020-09-04 13:42:28 -07:00 committed by Facebook GitHub Bot
parent 4131dcf012
commit dabb68c1e5
2 changed files with 13 additions and 5 deletions

View File

@ -37,9 +37,13 @@ def checkcommitmessage(ui, repo, **kwargs):
break
if badlines:
ui.warn(_("non-printable characters in commit message\n"))
ui.warn(_("+-------------------------------------------------------------\n"))
ui.warn(_("| Non-printable characters in commit message are not allowed.\n"))
ui.warn(_("| Edit your commit message to fix this issue.\n"))
ui.warn(_("| The problematic commit message can be found at:\n"))
for num, l in badlines:
ui.warn(_("Line {}: {!r}\n".format(num, l)))
ui.warn(_("| Line {}: {!r}\n".format(num, l)))
ui.warn(_("+-------------------------------------------------------------\n"))
# False means success
return bool(badlines)

View File

@ -20,9 +20,13 @@ sh % "cd repo"
sh % "touch a"
sh % 'hg commit -A -l "$TESTDIR/ctrlchar-msg.txt"' == r"""
adding a
non-printable characters in commit message
Line 5: 'This has a sneaky ctrl-A: \x01'
Line 6: 'And this has esc: \x1b'
+-------------------------------------------------------------
| 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"