fix: do not allow squash!
commits when merging (#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 commit is contained in:

committed by
Kara Erickson

parent
2b289250d8
commit
c0d5684078
@ -144,5 +144,38 @@ describe('validate-commit-message.js', () => {
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('(squash)', () => {
|
||||
|
||||
it('should strip the `squash! ` 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('squash! feat(core): add feature')).toBe(VALID);
|
||||
expect(validateMessage('squash! fix: a bug', false)).toBe(VALID);
|
||||
|
||||
// Invalid messages.
|
||||
expect(validateMessage('squash! fix a typo', false)).toBe(INVALID);
|
||||
expect(validateMessage('squash! squash! fix: a bug')).toBe(INVALID);
|
||||
expect(errors).toEqual([
|
||||
errorMessageFor('squash! fix a typo'),
|
||||
errorMessageFor('squash! squash! fix: a bug'),
|
||||
]);
|
||||
});
|
||||
|
||||
describe('with `disallowSquash`', () => {
|
||||
|
||||
it('should fail', () => {
|
||||
expect(validateMessage('fix: something', true)).toBe(VALID);
|
||||
expect(validateMessage('squash! fix: something', true)).toBe(INVALID);
|
||||
expect(errors).toEqual([
|
||||
'INVALID COMMIT MSG: squash! fix: something\n' +
|
||||
' => ERROR: The commit must be manually squashed into the target commit',
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user