From 847cd1a6fb4b5084da1ff7197be176619ecd239c Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Wed, 3 Jul 2019 11:53:33 +0200 Subject: [PATCH 1/2] Unmerged files will be counted as modified during "mgit status". --- lib/commands/status.js | 6 ++++- tests/commands/status.js | 54 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/lib/commands/status.js b/lib/commands/status.js index f1050e9..08dd08d 100644 --- a/lib/commands/status.js +++ b/lib/commands/status.js @@ -115,6 +115,10 @@ module.exports = { const wholeRowColor = status.branch !== 'master' ? 'magenta' : null; let branch = status.branch; + // Unmerged files are also modified so we should print the number of them out. + const modifiedFiles = [ status.modified, status.unmerged ] + .reduce( ( sum, item ) => sum + item.length, 0 ); + if ( mgitBranch !== status.branch ) { branch = `${ color( 'cyan', '!' ) } ${ branch }`; } @@ -132,7 +136,7 @@ module.exports = { } if ( status.modified.length ) { - statusColumn.push( color( 'red', `M${ status.modified.length }` ) ); + statusColumn.push( color( 'red', `M${ modifiedFiles }` ) ); } if ( status.untracked.length ) { diff --git a/tests/commands/status.js b/tests/commands/status.js index 9d46d0c..e7cc3bb 100644 --- a/tests/commands/status.js +++ b/tests/commands/status.js @@ -299,6 +299,7 @@ describe( 'commands/status', () => { staged: [], modified: [ 'README.md' ], untracked: [], + unmerged: [] }, mgitBranch: 'master', commit: 'abcd123' @@ -313,6 +314,7 @@ describe( 'commands/status', () => { staged: [ 'gulpfile.js' ], modified: [], untracked: [ 'CHANGELOG.md' ], + unmerged: [] }, mgitBranch: 't/1', commit: 'ef45678' @@ -363,6 +365,7 @@ describe( 'commands/status', () => { staged: [], modified: [], untracked: [], + unmerged: [] }, mgitBranch: 'master', commit: 'abcd123' @@ -391,6 +394,7 @@ describe( 'commands/status', () => { staged: [], modified: [], untracked: [], + unmerged: [] }, mgitBranch: 'master', commit: 'abcd123' @@ -419,6 +423,7 @@ describe( 'commands/status', () => { staged: [], modified: [], untracked: [], + unmerged: [] }, mgitBranch: 'master', commit: 'ef45678' @@ -471,11 +476,60 @@ describe( 'commands/status', () => { staged: [], modified: [], untracked: [], + unmerged: [] }, mgitBranch: 'master', commit }; } } ); + + it( 'counts unmerged files as modified', () => { + const logStub = sinon.stub( console, 'log' ); + + const processedPackages = new Set(); + const commandResponses = new Set(); + + processedPackages.add( '@ckeditor/ckeditor5-foo' ); + + commandResponses.add( { + packageName: 'foo', + status: { + branch: 'master', + ahead: 0, + behind: 2, + staged: [], + modified: [ 'README.md' ], + untracked: [], + unmerged: [ '.travis.yml' ] + }, + mgitBranch: 'master', + commit: 'abcd123' + } ); + + stubs.table.toString.returns( '┻━┻' ); + + statusCommand.afterExecute( processedPackages, commandResponses ); + + expect( stubs.table.constructor.firstCall.args[ 0 ] ).to.deep.equal( { + head: [ 'Package', 'Branch', 'Commit', 'Status' ], + style: { + compact: true + } + } ); + + expect( stubs.table.push.firstCall.args[ 0 ] ).to.deep.equal( + [ 'foo', 'master ↓2', 'abcd123', 'M2' ] + ); + + expect( stubs.table.toString.calledOnce ).to.equal( true ); + + expect( logStub.calledTwice ).to.equal( true ); + expect( logStub.firstCall.args[ 0 ] ).to.equal( '┻━┻' ); + expect( logStub.secondCall.args[ 0 ] ).to.match( /^Legend:/ ); + expect( stubs.chalk.cyan.calledOnce ).to.equal( true ); + + logStub.restore(); + } ); } ); } ); From dd5417139a3879c68242c11c583953910831a8ab Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Mon, 15 Jul 2019 11:24:26 +0200 Subject: [PATCH 2/2] Fixed "if" condition in "status/afterExecute()". --- lib/commands/status.js | 2 +- tests/commands/status.js | 48 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/lib/commands/status.js b/lib/commands/status.js index 08dd08d..c00d4b4 100644 --- a/lib/commands/status.js +++ b/lib/commands/status.js @@ -135,7 +135,7 @@ module.exports = { statusColumn.push( color( 'green', `+${ status.staged.length }` ) ); } - if ( status.modified.length ) { + if ( modifiedFiles ) { statusColumn.push( color( 'red', `M${ modifiedFiles }` ) ); } diff --git a/tests/commands/status.js b/tests/commands/status.js index e7cc3bb..5dbbf54 100644 --- a/tests/commands/status.js +++ b/tests/commands/status.js @@ -531,5 +531,53 @@ describe( 'commands/status', () => { logStub.restore(); } ); + + it( 'counts unmerged files as modified even if number of modified files is equal 0', () => { + const logStub = sinon.stub( console, 'log' ); + + const processedPackages = new Set(); + const commandResponses = new Set(); + + processedPackages.add( '@ckeditor/ckeditor5-foo' ); + + commandResponses.add( { + packageName: 'foo', + status: { + branch: 'master', + ahead: 0, + behind: 2, + staged: [], + modified: [], + untracked: [], + unmerged: [ '.travis.yml' ] + }, + mgitBranch: 'master', + commit: 'abcd123' + } ); + + stubs.table.toString.returns( '┻━┻' ); + + statusCommand.afterExecute( processedPackages, commandResponses ); + + expect( stubs.table.constructor.firstCall.args[ 0 ] ).to.deep.equal( { + head: [ 'Package', 'Branch', 'Commit', 'Status' ], + style: { + compact: true + } + } ); + + expect( stubs.table.push.firstCall.args[ 0 ] ).to.deep.equal( + [ 'foo', 'master ↓2', 'abcd123', 'M1' ] + ); + + expect( stubs.table.toString.calledOnce ).to.equal( true ); + + expect( logStub.calledTwice ).to.equal( true ); + expect( logStub.firstCall.args[ 0 ] ).to.equal( '┻━┻' ); + expect( logStub.secondCall.args[ 0 ] ).to.match( /^Legend:/ ); + expect( stubs.chalk.cyan.calledOnce ).to.equal( true ); + + logStub.restore(); + } ); } ); } );