File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff 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' , ( ) => {
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import {Commit, parseCommitMessage} from './parse.js';
1515/** Options for commit message validation. */
1616export 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: ' +
You can’t perform that action at this time.
0 commit comments