import cp from 'child_process'; export function mockgit(branch = '') { let spy = jasmine.createSpy('git'); spyOn(cp, 'execFileSync').and.callFake(function(file, args = [], options) { if (file === 'git') { let result = spy(...args) ?? ''; if (!args.includes('show') && !args.includes('rev-parse')) return ''; if (!args.includes('rev-parse')) return result; if (args.includes('--abbrev-ref')) return branch; return result.match(/^COMMIT_SHA:(.*)$/m)?.[1]; } else { return cp.execFileSync.and.originalFn.call(this, file, args, options); } }); spyOn(cp, 'execSync').and.callFake(function(cmd, options) { if (cmd.match(/^pwd\b/) || cmd.match(/^cd\b/)) { return ''; } else { return cp.execSync.and.originalFn.call(this, cmd, options); } }); return spy; }