Skip to content

Commit f539bdf

Browse files
committed
Ignore the squash! autosquash flag in subject
Because: * `git-commit` uses a `squash!` prefix as a flag for autosquash with interactive rebase. * The interactive rebase will strip the prefix, so the validation should ignore it when checking the subject for line length, capitalisation, etc. This change: * Strips the `squash!` prefix from the commit subject before validating. * Adds tests for both the subject length and capitialisation validations with the `squash!` prefix.
1 parent d217f02 commit f539bdf

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

hook.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ validate_commit_message() {
110110
# reset warnings
111111
WARNINGS=()
112112

113-
# capture the subject
114-
COMMIT_SUBJECT=${COMMIT_MSG_LINES[0]}
113+
# capture the subject, and remove the 'squash! ' prefix if present
114+
COMMIT_SUBJECT=${COMMIT_MSG_LINES[0]/#squash! /}
115115

116116
# if the commit is empty there's nothing to validate, we can return here
117117
COMMIT_MSG_STR="${COMMIT_MSG_LINES[*]}"

test/validation.bats

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ EOF
9696
assert_line --partial "Limit the subject line to 50 characters (51 chars)"
9797
}
9898

99+
@test "validation: ignores squash! prefix when checking subject line length" {
100+
echo "n" > $FAKE_TTY
101+
run git commit -m "squash! Add foo bar string to my_file - As requested by Jo"
102+
103+
assert_success
104+
refute_line --partial "Limit the subject line to 50 characters"
105+
}
106+
99107
# 3. Capitalize the subject line
100108
# ------------------------------------------------------------------------------
101109

@@ -131,6 +139,14 @@ EOF
131139
refute_line --partial "Capitalize the subject line"
132140
}
133141

142+
@test "validation: ignores squash! prefix when checking subject line capitalisation" {
143+
echo "n" > $FAKE_TTY
144+
run git commit -m "squash! Add foo bar string to my_file"
145+
146+
assert_success
147+
refute_line --partial "Capitalize the subject line"
148+
}
149+
134150
# 4. Do not end the subject line with a period
135151
# ------------------------------------------------------------------------------
136152

0 commit comments

Comments
 (0)