Skip to content

Commit 43f75c5

Browse files
committed
Ignore commits with the fixup! autosquash flag
Because: * `git-commit` uses a `fixup!` prefix as a flag for autosquash with interactive rebase. * The interactive rebase will set the commit to fixup, which will discard the commit message, so there's no need to validate if the flag is present at the start of the subject. This change: * Checks for the `fixup!` prefix in the subject and breaks out of the validation if present. * Adds a test to verify the validation is skipped.
1 parent f539bdf commit 43f75c5

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

hook.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ validate_commit_message() {
115115

116116
# if the commit is empty there's nothing to validate, we can return here
117117
COMMIT_MSG_STR="${COMMIT_MSG_LINES[*]}"
118-
test -n "${COMMIT_MSG_STR[*]// }" || return;
118+
test -z "${COMMIT_MSG_STR[*]// }" && return;
119+
120+
# if the commit subject starts with 'fixup! ' there's nothing to validate, we can return here
121+
[[ $COMMIT_SUBJECT == 'fixup! '* ]] && return;
119122

120123
# 1. Separate subject from body with a blank line
121124
# ------------------------------------------------------------------------------

test/validation.bats

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ EOF
2424
assert_success
2525
}
2626

27+
@test "validation: ignores commits with the fixup! autosquash flag" {
28+
echo "n" > $FAKE_TTY
29+
run git commit -m "$(cat <<EOF
30+
fixup! Add foo bar string to my_file - As requested by Jon
31+
Another line in the body that runs to longer than 72 characters in length
32+
EOF
33+
)"
34+
35+
assert_success
36+
}
37+
2738
# 0. Good commits - control
2839
# ------------------------------------------------------------------------------
2940

0 commit comments

Comments
 (0)