meta:hooks:commit-msg: Break on first comment
Because `git diff --staged -u | head -1` returns nothing when rebasing the hook checked the line length of the commit changes (verbose commit).
This commit is contained in:
@@ -15,7 +15,10 @@ die() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
subject="$(head -1 "$1")"
|
subject="$(head -1 "$1")"
|
||||||
body="$(tail +2 "$1" | grep -v "^#")"
|
# Because of potential long lines in the changes (when using verbose commit) or
|
||||||
|
# comments (for example when rebasing), everything until the first comment is
|
||||||
|
# interpreted as body.
|
||||||
|
body="$(tail +2 "$1" | sed -n '/^#/q;p')"
|
||||||
|
|
||||||
[[ ${#subject} -le 50 ]] || die "Subject too long. (<= 50)\n"
|
[[ ${#subject} -le 50 ]] || die "Subject too long. (<= 50)\n"
|
||||||
|
|
||||||
@@ -42,13 +45,7 @@ done
|
|||||||
BKP_IFS="$IFS"
|
BKP_IFS="$IFS"
|
||||||
IFS='
|
IFS='
|
||||||
'
|
'
|
||||||
# The -v flag or commit.verbose setting add the changes of the commit to the
|
for line in $($body); do
|
||||||
# bottom of the commit message. But when the changes contain lines longer than
|
|
||||||
# 72 characters this hook will fail when not breaking the loop before the end
|
|
||||||
# start of the patch.
|
|
||||||
verbose_start_line="$(git diff --staged -u | head -1)"
|
|
||||||
for line in $body; do
|
|
||||||
[[ "$line" != "$verbose_start_line" ]] || break
|
|
||||||
[[ ${#line} -le 72 ]] || die "Body lines too long. (<= 72)\n"
|
[[ ${#line} -le 72 ]] || die "Body lines too long. (<= 72)\n"
|
||||||
done
|
done
|
||||||
IFS="$BKP_IFS"
|
IFS="$BKP_IFS"
|
||||||
|
|||||||
Reference in New Issue
Block a user