Skip to content

Commit

Permalink
update to pre-commit-hook opt outs, #1350
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Oct 24, 2024
1 parent 15cb32b commit f339245
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions js/scripts/hook-pre-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const optOutRepos = [
// Console logging via --console
const commandLineArguments = process.argv.slice( 2 );
const outputToConsole = commandLineArguments.includes( '--console' );
const force = commandLineArguments.includes( '--force' );

( async () => {

Expand All @@ -51,22 +52,23 @@ const outputToConsole = commandLineArguments.includes( '--console' );

// By default, run all tasks
const tasksToRun = [ 'lint', 'report-media', 'check', 'qunit', 'phet-io-api-compare' ];
const OPT_OUT_ALL = '*'; // Key to opt out of all tasks

// check local preferences for overrides for which tasks to turn 'off'
const gitHooks = buildLocal.gitHooks;
if ( gitHooks ) {
Object.keys( gitHooks ).forEach( key => {
if ( gitHooks[ key ] === 'off' ) {
if ( key === '*' ) {
outputToConsole && console.log( 'turning off all tasks' );
tasksToRun.length = 0;
}
else {
outputToConsole && console.log( 'turning off task:', key );
const hookPreCommit = buildLocal.hookPreCommit;
if ( hookPreCommit && !force ) {
if ( hookPreCommit[ OPT_OUT_ALL ] === false ) {
outputToConsole && console.log( 'all tasks opted out' );
tasksToRun.length = 0;
}
else {
Object.keys( hookPreCommit ).forEach( key => {
if ( hookPreCommit[ key ] === false && tasksToRun.indexOf( key ) >= 0 ) {
outputToConsole && console.log( 'task opted out:', key );
tasksToRun.splice( tasksToRun.indexOf( key ), 1 );
}
}
} );
} );
}
}

const precommitSuccess = await phetTimingLog.startAsync( `hook-pre-commit repo="${repo}"`, async () => {
Expand Down

0 comments on commit f339245

Please sign in to comment.