Skip to content

Latest commit

 

History

History
32 lines (23 loc) · 861 Bytes

git-version.md

File metadata and controls

32 lines (23 loc) · 861 Bytes

Check if git is installed

To check if git (or the customBinary of your choosing) is accessible, use the git.version() API:

import { simpleGit } from 'simple-git';

const {installed} = await simpleGit().version();
if (!installed) {
  throw new Error(`Exit: "git" not available.`);
}

// ... continue using Git commands here

Check for a specific version of git

Using the git.version() interface, you can query for the current git version information split by major, minor and patch:

import { simpleGit } from 'simple-git';
import { lt } from 'semver';

const versionResult = await simpleGit().version();
if (lt(String(versionResult), '2.1.0')) {
  throw new Error(`Exit: "git" must be at least version 2.1.0.`);
}

// ... continue using Git commands here that are compatible with 2.1.0 or higher