Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mgit should end with proper exit code if some command failed #90

Merged
merged 3 commits into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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