Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,9 @@ Message](https://cbea.ms/git-commit/).
6. Wrap the body at 72 characters.
7. Use the body to explain what and why, not how.

A body line may exceed 72 characters when everything past that column is part
of one word containing an http or https URL, since a URL cannot be wrapped.

An example (derived from Chris' blog post) looks like the following:
```text
Summarize changes in around 50 characters or less
Expand Down
16 changes: 12 additions & 4 deletions scripts/git-commit-msg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,20 @@ if [ -n "$body" ] && [ -n "$second" ]; then
error "separate the subject from the body with a blank line"
fi

# Rule 6.
wide=0
# Rule 6, except where everything past column 72 is part of one word containing
# an http or https URL. Only the first 72 characters are searched for where that
# word begins, because ##*[[:space:]] over the whole line is quadratic in its
# length.
while IFS= read -r line; do
[ "${#line}" -le 72 ] || wide=1
[ "${#line}" -gt 72 ] || continue
head=${line:0:72}
case "${head##*[[:space:]]}${line:72}" in
*[[:space:]]*) ;;
*http://?* | *https://?*) continue ;;
esac
error "body lines must not exceed 72 characters"
break
done <<< "$body"
[ "$wide" -eq 0 ] || error "body lines must not exceed 72 characters"

# Rule 7, in the one form that can be decided by looking: a body that opens a
# section announcing it is about to describe the mechanism. A regex, where the
Expand Down
44 changes: 44 additions & 0 deletions scripts/test-git-hooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,50 @@ Body on the second line.
' 'blank line'
expect_fail 'body over 72' 'Add a syscall

This body line is quite deliberately wider than the seventy-two column limit.
' 'exceed 72'
for scheme in http https; do
expect_ok "wide $scheme URL on its own line" "Add a syscall

$scheme://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
"
done
for scheme in ftp git s3; do
expect_fail "wide $scheme URL on its own line" "Add a syscall

$scheme://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
" 'exceed 72'
done
expect_fail 'wide path without a scheme' 'Add a syscall

www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
' 'exceed 72'
expect_ok 'wide https URL closing a normal message' 'Add a syscall

The guest calls it during startup and stops when it gets ENOSYS back,
so every program built against a newer libc exits before reaching main.

See https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
'
expect_ok 'wide https URL in parentheses' 'Add a syscall

See the thread (https://github.com/sysprog21/elfuse/issues/187#issuecomment-12345678).
'
expect_ok 'https URL starting at column 73' 'Add a syscall

12345678901234567890123456789012345678901234567890123456789012345678901 https://x.y/z
'
expect_fail 'prose through column 72 before an https URL' 'Add a syscall

123456789012345678901234567890123456789012345678901234567890123456789012 https://x.y/z
' 'exceed 72'
expect_fail 'prose after a wide https URL' 'Add a syscall

See https://github.com/sysprog21/elfuse/issues/187#issuecomment-1234567890 here
' 'exceed 72'
expect_fail 'wide prose after a wide https URL' 'Add a syscall

https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
This body line is quite deliberately wider than the seventy-two column limit.
' 'exceed 72'
expect_fail 'body describes how' 'Add a syscall
Expand Down
Loading