Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F2341638
D1419.largetrue.id.diff
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Apr 16, 6:11 PM
Size
2 KB
Mime Type
application/octet-stream
Expires
Sun, Apr 17, 6:11 PM (1 d)
Engine
blob
Format
Raw Data
Handle
1290828
Attached To
D1419: checkmessagehook: print more detail on what bad chars were found
D1419.largetrue.id.diff
View Options
diff --git a/hgext3rd/checkmessagehook.py b/hgext3rd/checkmessagehook.py
--- a/hgext3rd/checkmessagehook.py
+++ b/hgext3rd/checkmessagehook.py
@@ -17,10 +17,17 @@
return True
printable = set(string.printable)
- for c in hg_commit_message:
- if ord(c) < 128 and c not in printable:
- ui.warn(_('non-printable characters in commit message\n'))
- return True
+ badlines = []
+ for lnum, line in enumerate(hg_commit_message.splitlines()):
+ for c in line:
+ if ord(c) < 128 and c not in printable:
+ badlines.append((lnum + 1, line))
+ break
+
+ if badlines:
+ ui.warn(_('non-printable characters in commit message\n'))
+ for num, l in badlines:
+ ui.warn(_('Line {}: {!r}\n'.format(num, l)))
# False means success
- return False
+ return bool(badlines)
diff --git a/tests/ctrlchar-msg.txt b/tests/ctrlchar-msg.txt
new file mode 100644
--- /dev/null
+++ b/tests/ctrlchar-msg.txt
@@ -0,0 +1,8 @@
+This is a commit with bad chars in the message - but this one is OK
+
+That was a blank line
+
+This has a sneaky ctrl-A:
+And this has esc:
+
+Finish off with an OK line
diff --git a/tests/perfectlyok-msg.txt b/tests/perfectlyok-msg.txt
new file mode 100644
--- /dev/null
+++ b/tests/perfectlyok-msg.txt
@@ -0,0 +1 @@
+This commit message is perfectly OK, and has no sneaky control characters.
diff --git a/tests/test-checkmessagehook.t b/tests/test-checkmessagehook.t
new file mode 100644
--- /dev/null
+++ b/tests/test-checkmessagehook.t
@@ -0,0 +1,28 @@
+ $ cat >> $HGRCPATH <<EOF
+ > [extensions]
+ > checkmessagehook = $TESTDIR/../hgext3rd/checkmessagehook.py
+ > EOF
+
+Build up a repo
+
+ $ hg init repo
+ $ cd repo
+ $ touch a
+ $ hg commit -A -l $TESTDIR/ctrlchar-msg.txt
+ adding a
+ non-printable characters in commit message
+ Line 5: 'This has a sneaky ctrl-A: \x01'
+ Line 6: 'And this has esc: \x1b'
+ transaction abort!
+ rollback completed
+ abort: pretxncommit.checkmessage hook failed
+ [255]
+ $ hg commit -A -l $TESTDIR/perfectlyok-msg.txt
+ adding a
+ $ hg log -r .
+ changeset: 0:d9cf9881be7b
+ tag: tip
+ user: test
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: This commit message is perfectly OK, and has no sneaky control characters.
+
Event Timeline
Log In to Comment