diff --git a/packages/env/src/utils.js b/packages/env/src/utils.js index 2b99933ee..a336f011a 100644 --- a/packages/env/src/utils.js +++ b/packages/env/src/utils.js @@ -13,6 +13,9 @@ const GIT_COMMIT_FORMAT = [ ].join('%n'); // git show format uses %n for newlines. export function git(args) { + if (process.env.PERCY_SKIP_GIT_CHECK === 'true') { + return ''; + } try { return cp.execSync(`git ${args}`, { stdio: ['ignore', 'pipe', 'ignore'], diff --git a/packages/env/test/defaults.test.js b/packages/env/test/defaults.test.js index 8146f8e8f..121924cbc 100644 --- a/packages/env/test/defaults.test.js +++ b/packages/env/test/defaults.test.js @@ -171,4 +171,20 @@ describe('Defaults', () => { expect(env).toHaveProperty('git.sha', null); }); + + describe('env PERCY_SKIP_GIT_CHECK', () => { + beforeEach(() => { + process.env.PERCY_SKIP_GIT_CHECK = true; + }); + + afterAll(() => { + process.env.PERCY_SKIP_GIT_CHECK = false; + }); + + it('does not make git commands when set to true', () => { + mockgit('mock branch').and.returnValue(''); + + expect(env).toHaveProperty('git.sha', null); + }); + }); });