Skip to content

Commit

Permalink
[PER-2582] Do not execute git commands when PERCY_SKIP_GIT_CHECK is…
Browse files Browse the repository at this point in the history
… set to True (#1400)
  • Loading branch information
shantanuk-browserstack authored Oct 18, 2023
1 parent 932d9ce commit da60154
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/env/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
16 changes: 16 additions & 0 deletions packages/env/test/defaults.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit da60154

Please sign in to comment.