Skip to content

Commit fe58c3e

Browse files
authored
feat(ng-dev): introduce an option to disable fixup commits in commit validation (#2541)
Some repositories do not allow fixup commits. This feature adds a configuration option to disallow such commits during the validation process.
1 parent 5b4b2a6 commit fe58c3e

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

ng-dev/commit-message/validate.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,33 @@ describe('validate-commit-message.js', () => {
266266
);
267267
});
268268
});
269+
270+
describe('with `disallowFixup`', () => {
271+
it('when true should fail', async () => {
272+
const msg = 'fixup! foo';
273+
274+
expectValidationResult(
275+
await validateCommitMessage(msg, {
276+
disallowFixup: true,
277+
nonFixupCommitHeaders: ['foo', 'bar', 'baz'],
278+
}),
279+
INVALID,
280+
['The commit must be manually fixed-up into the target commit as fixup commits are disallowed'],
281+
);
282+
});
283+
284+
it('when false should pass', async () => {
285+
const msg = 'fixup! foo';
286+
287+
expectValidationResult(
288+
await validateCommitMessage(msg, {
289+
disallowFixup: false,
290+
nonFixupCommitHeaders: ['foo', 'bar', 'baz'],
291+
}),
292+
VALID,
293+
);
294+
});
295+
});
269296
});
270297

271298
describe('minBodyLength', () => {

ng-dev/commit-message/validate.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {Commit, parseCommitMessage} from './parse.js';
1515
/** Options for commit message validation. */
1616
export interface ValidateCommitMessageOptions {
1717
disallowSquash?: boolean;
18+
disallowFixup?: boolean;
1819
nonFixupCommitHeaders?: string[];
1920
}
2021

@@ -90,6 +91,14 @@ export async function validateCommitMessage(
9091
// stripping the `fixup! ` prefix), otherwise we assume this verification will happen in another
9192
// check.
9293
if (commit.isFixup) {
94+
if (options.disallowFixup) {
95+
errors.push(
96+
'The commit must be manually fixed-up into the target commit as fixup commits are disallowed',
97+
);
98+
99+
return false;
100+
}
101+
93102
if (options.nonFixupCommitHeaders && !options.nonFixupCommitHeaders.includes(commit.header)) {
94103
errors.push(
95104
'Unable to find match for fixup commit among prior commits: ' +

0 commit comments

Comments
 (0)