Previously, `validate-commit-message` would treat `fixup! `-prefixed
commits like this:
- It would strip the `fixup! ` prefix.
- It would validate the rest of the commit message header as any other
commit.
However, fixup commits are special in that they need to exactly match an
earlier commit message header (sans the `fixup! ` prefix) in order for
git to treat them correctly. Otherwise, they will not be squashed into
the original commits and will be merged as is. Fixup commits can end up
not matching their original commit for several reasons (e.g. accidental
typo, changing the original commit message, etc.).
This commit prevents invalid fixup commits to pass validation by
ensuring that they match an earlier (unmerged) commit (i.e. a commit
between the current HEAD and the BASE commit).
NOTE: This new behavior is currently not activated in the pre-commit git
hook, that is used to validate commit messages (because the
preceding, unmerged commits are not available there). It _is_
activated in `gulp validate-commit-message`, which is run as part
of the `lint` job on CI and thus will detect invalid commits,
before their getting merged.
PR Close#32023
While `fixup! ` is fine, `squash! ` means that the commit message needs
tweaking, which cannot be done automatically during merging (i.e. it
should be done by the PR author).
Previously, `validate-commit-message` would always allow
`squash! `-prefixed commits, which would cause problems during merging.
This commit changes `validate-commit-message` to make it configurable
whether such commits are allowed and configures the
`gulp validate-commit-message` task, which is run as part of the `lint`
job on CI, to not allow them.
NOTE: This new check is disabled in the pre-commit git hook that is used
to validate commit messages, because these commits might still be
useful during development.
PR Close#32023
This patch adds the gulp command of `validate-commit-messages`
which will validate the range of commits messages present in the
active branch.
This check now runs on CI as part of the linting checks.
Allowed commit message types and scopes are controlled via commit-message.json file
and documented at https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-guidelines
This solution is based on old Vojta's code that he wrote for angular/angular.js, that was later adjusted
by @matsko in #13815.
Ideally we should switch over to something like https://www.npmjs.com/package/commitplease
as suggested in #9953 but that package currently doesn't support strict scope checking,
which is one of the primarily goal of this PR.
Note that this PR removes support for "chore" which was previously overused
by everyone on the team.
Closes#13815Fixes#3337