Skip to content

Commit

Permalink
Merge pull request #90 from cksource/t/86
Browse files Browse the repository at this point in the history
Fix: Mgit should end with proper exit code if some command failed. Closes #86.
  • Loading branch information
Reinmar committed Nov 19, 2018
2 parents 4fdc134 + ed6a88f commit b7b878b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 13 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = function( args, options ) {

const processedPackages = new Set();
const commandResponses = new Set();
const packagesWithError = new Set();
const packageNames = getPackageNames( options );

let allPackagesNumber = packageNames.length;
Expand Down Expand Up @@ -97,6 +98,10 @@ module.exports = function( args, options ) {
}

if ( returnedData.logs ) {
if ( returnedData.logs.error.length ) {
packagesWithError.add( packageName );
}

logDisplay( packageName, returnedData.logs, {
current: donePackagesNumber,
all: allPackagesNumber,
Expand Down Expand Up @@ -125,6 +130,14 @@ module.exports = function( args, options ) {
const endTime = process.hrtime( startTime );

console.log( chalk.cyan( `Execution time: ${ endTime[ 0 ] }s${ endTime[ 1 ].toString().substring( 0, 3 ) }ms.` ) );

if ( packagesWithError.size ) {
const repositoryForm = packagesWithError.size === 1 ? 'repository' : 'repositories';
const message = `\n❗❗❗ The command failed to execute in ${ packagesWithError.size } ${ repositoryForm }.\n`;

console.log( chalk.red( message ) );
process.exit( 1 );
}
} );
}
};
2 changes: 0 additions & 2 deletions lib/utils/displaylog.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ module.exports = function displayLog( packageName, logs, options ) {
}

if ( errorLogs ) {
process.exitCode = 1;

console.log( chalk.red( errorLogs ) );
}

Expand Down

0 comments on commit b7b878b

Please sign in to comment.