build: ensure fixup commits match an earlier, unmerged commit (#32023)
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
This commit is contained in:
committed by
Kara Erickson
parent
c0d5684078
commit
3df54be9e4
@@ -177,5 +177,58 @@ describe('validate-commit-message.js', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('(fixup)', () => {
|
||||
|
||||
describe('without `nonFixupCommitHeaders`', () => {
|
||||
|
||||
it('should strip the `fixup! ` prefix and validate the rest', () => {
|
||||
const errorMessageFor = header =>
|
||||
`INVALID COMMIT MSG: ${header}\n => ERROR: The commit message header does not match the format of ` +
|
||||
'\'<type>(<scope>): <subject>\' or \'Revert: "<type>(<scope>): <subject>"\'';
|
||||
|
||||
// Valid messages.
|
||||
expect(validateMessage('fixup! feat(core): add feature')).toBe(VALID);
|
||||
expect(validateMessage('fixup! fix: a bug')).toBe(VALID);
|
||||
|
||||
// Invalid messages.
|
||||
expect(validateMessage('fixup! fix a typo')).toBe(INVALID);
|
||||
expect(validateMessage('fixup! fixup! fix: a bug')).toBe(INVALID);
|
||||
expect(errors).toEqual([
|
||||
errorMessageFor('fixup! fix a typo'),
|
||||
errorMessageFor('fixup! fixup! fix: a bug'),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with `nonFixupCommitHeaders`', () => {
|
||||
|
||||
it('should check that the fixup commit matches a non-fixup one', () => {
|
||||
const msg = 'fixup! foo';
|
||||
|
||||
expect(validateMessage(msg, false, ['foo', 'bar', 'baz'])).toBe(VALID);
|
||||
expect(validateMessage(msg, false, ['bar', 'baz', 'foo'])).toBe(VALID);
|
||||
expect(validateMessage(msg, false, ['baz', 'foo', 'bar'])).toBe(VALID);
|
||||
|
||||
expect(validateMessage(msg, false, ['qux', 'quux', 'quuux'])).toBe(INVALID);
|
||||
expect(errors).toEqual([
|
||||
`INVALID COMMIT MSG: ${msg}\n` +
|
||||
' => ERROR: Unable to find match for fixup commit among prior commits: \n' +
|
||||
' qux\n' +
|
||||
' quux\n' +
|
||||
' quuux',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should fail if `nonFixupCommitHeaders` is empty', () => {
|
||||
expect(validateMessage('refactor(router): make reactive', false, [])).toBe(VALID);
|
||||
expect(validateMessage('fixup! foo', false, [])).toBe(INVALID);
|
||||
expect(errors).toEqual([
|
||||
'INVALID COMMIT MSG: fixup! foo\n' +
|
||||
' => ERROR: Unable to find match for fixup commit among prior commits: -',
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user