use System.run for logging Git diff

This commit is contained in:
dogboydog 2020-07-08 20:36:57 -04:00 committed by Webber Takken
parent 91ec427695
commit fdf71758a9
3 changed files with 8 additions and 6 deletions

File diff suppressed because one or more lines are too long

View File

@ -57,7 +57,10 @@ export default class Versioning {
* Log up to maxDiffLines of the git diff.
*/
static async logDiff() {
this.git(['--no-pager', 'diff', '|', 'head', '-n', this.maxDiffLines.toString()]);
await System.run('sh', undefined, {
input: Buffer.from(`git --no-pager diff | head -n ${this.maxDiffLines.toString()}`),
silent: false,
});
}
/**

View File

@ -111,15 +111,14 @@ describe('Versioning', () => {
.spyOn(Versioning, 'parseSemanticVersion')
.mockResolvedValue({ tag: 'mocktag', commits: 'abcdef', hash: '75822BCAF' });
const logDiffSpy = jest.spyOn(Versioning, 'logDiff');
const gitSpy = jest
.spyOn(Versioning, 'git')
.mockReturnValue('There is a diff actually! \n M My_Dirty_File.txt');
const gitSpy = jest.spyOn(System, 'run').mockResolvedValue({});
await Versioning.generateSemanticVersion();
expect(logDiffSpy).toHaveBeenCalledTimes(1);
expect(gitSpy).toHaveBeenCalledTimes(1);
expect(Versioning.git.mock.calls[0][0].indexOf('diff')).toBeGreaterThan(-1);
const issuedCommand = System.run.mock.calls[0][2].input.toString();
expect(issuedCommand.indexOf('diff')).toBeGreaterThan(-1);
});
});