-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check Git version during install (#656)
- Loading branch information
Showing
5 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
jest.mock('child_process') | ||
|
||
import cp from 'child_process' | ||
import { checkGitVersion } from '../checkGitVersion' | ||
|
||
describe('checkGitVersion', (): void => { | ||
it('should throw an error if version <2.13.0', (): void => { | ||
// eslint-disable-next-line | ||
// @ts-ignore | ||
cp.spawnSync.mockReturnValue({ | ||
status: 0, | ||
stdout: Buffer.from('git version 2.12.0') | ||
}) | ||
expect(() => checkGitVersion()).toThrowError() | ||
}) | ||
|
||
it('should not throw an error if version >=2.13.0', (): void => { | ||
// eslint-disable-next-line | ||
// @ts-ignore | ||
cp.spawnSync.mockReturnValue({ | ||
status: 0, | ||
stdout: Buffer.from('git version 2.14.0') | ||
}) | ||
expect(() => checkGitVersion()).not.toThrowError() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import cp = require('child_process') | ||
import findVersions from 'find-versions' | ||
import compareVersions from 'compare-versions' | ||
|
||
export function checkGitVersion(): void { | ||
const { status, stderr, stdout } = cp.spawnSync('git', ['--version']) | ||
|
||
if (status !== 0) { | ||
throw new Error(stderr.toString()) | ||
} | ||
|
||
const [version] = findVersions(stdout.toString()) | ||
|
||
if (compareVersions(version, '2.13.0') === -1) { | ||
throw new Error(`Husky requires Git >=2.13.0. Got v${version}.`) | ||
} | ||
} |