Skip to content

Commit

Permalink
Merge pull request #108 from cksource/t/107
Browse files Browse the repository at this point in the history
Fix: Number of unmerged files will be shown as "modified" in the table while execution the status command. Closes #107.
  • Loading branch information
Reinmar authored Jul 15, 2019
2 parents 51eded0 + dd54171 commit 5481260
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/commands/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }`;
}
Expand All @@ -131,8 +135,8 @@ module.exports = {
statusColumn.push( color( 'green', `+${ status.staged.length }` ) );
}

if ( status.modified.length ) {
statusColumn.push( color( 'red', `M${ status.modified.length }` ) );
if ( modifiedFiles ) {
statusColumn.push( color( 'red', `M${ modifiedFiles }` ) );
}

if ( status.untracked.length ) {
Expand Down
102 changes: 102 additions & 0 deletions tests/commands/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ describe( 'commands/status', () => {
staged: [],
modified: [ 'README.md' ],
untracked: [],
unmerged: []
},
mgitBranch: 'master',
commit: 'abcd123'
Expand All @@ -313,6 +314,7 @@ describe( 'commands/status', () => {
staged: [ 'gulpfile.js' ],
modified: [],
untracked: [ 'CHANGELOG.md' ],
unmerged: []
},
mgitBranch: 't/1',
commit: 'ef45678'
Expand Down Expand Up @@ -363,6 +365,7 @@ describe( 'commands/status', () => {
staged: [],
modified: [],
untracked: [],
unmerged: []
},
mgitBranch: 'master',
commit: 'abcd123'
Expand Down Expand Up @@ -391,6 +394,7 @@ describe( 'commands/status', () => {
staged: [],
modified: [],
untracked: [],
unmerged: []
},
mgitBranch: 'master',
commit: 'abcd123'
Expand Down Expand Up @@ -419,6 +423,7 @@ describe( 'commands/status', () => {
staged: [],
modified: [],
untracked: [],
unmerged: []
},
mgitBranch: 'master',
commit: 'ef45678'
Expand Down Expand Up @@ -471,11 +476,108 @@ 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();
} );

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();
} );
} );
} );

0 comments on commit 5481260

Please sign in to comment.