-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprepare-commit-msg
More file actions
executable file
·30 lines (23 loc) · 1.08 KB
/
prepare-commit-msg
File metadata and controls
executable file
·30 lines (23 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
# Auto-wraps the commit message body to the length allowed by gitlint.
# Does not special-case the commit title because it cannot be fixed automatically;
# wrapping is not allowed there. If needed, gitlint's `commit-msg` hook will
# give us a chance to edit interactively.
#
# This runs after the commit message has been entered (even if with "git commit -m ...")
# but before gitlint runs in the commit-msg hook.
COMMIT_MSG_FILE=$1
_COMMIT_SOURCE=$2
_SHA1=$3
WIDTH=80
# Re-wraps file $1 to $WIDTH characters per line, using prettier, in-place.
rewrap() {
# Suppress the output of prettier, as it's overly verbose. Show only on failure.
prettier --no-config --no-editorconfig --prose-wrap always --print-width "$WIDTH" --write "$1" >/tmp/prettier.out \
|| { cat /tmp/prettier.out; exit 1; }
}
# If gitlint is already happy, do nothing
gitlint <"$COMMIT_MSG_FILE" >/tmp/gitlint.out 2>&1 && exit 0
# If this is a fixup commit, do nothing
<"$1" head -n1 | grep -q 'fixup!' && exit 0
echo "Rewrapping \"$(<"$COMMIT_MSG_FILE" head -n1 | cut -c-50)[...]\" to $WIDTH chars per line"