diff --git a/git/services/getPreviousVersions.js b/git/services/getPreviousVersions.js index 4f8d75c4..c7cea5fa 100644 --- a/git/services/getPreviousVersions.js +++ b/git/services/getPreviousVersions.js @@ -3,6 +3,8 @@ const child = require('child_process'); const semver = require('semver'); +const GIT = process.env.GIT_BIN || 'git'; + /** * Get a collection of all the previous versions sorted by semantic version * @@ -20,7 +22,7 @@ module.exports = function getPreviousVersions(decorateVersion, packageInfo) { // not contain all commits when cloned with git clone --depth=... // Needed e.g. for Travis const repo_url = packageInfo.repository.url; - const tagResults = child.spawnSync('git', ['ls-remote', '--tags', repo_url], {encoding: 'utf8'}); + const tagResults = child.spawnSync(GIT, ['ls-remote', '--tags', repo_url], {encoding: 'utf8'}); if (tagResults.status !== 0) { return []; } diff --git a/git/services/versionInfo.js b/git/services/versionInfo.js index 1c066ff7..53ade18b 100644 --- a/git/services/versionInfo.js +++ b/git/services/versionInfo.js @@ -3,6 +3,8 @@ const child = require('child_process'); const semver = require('semver'); +const GIT = process.env.GIT_BIN || 'git'; + let currentVersion, currentPackage, previousVersions; /** * Check the version is satisfactory. @@ -25,7 +27,7 @@ function satisfiesVersion(version) { * @return {String} The codename if found, otherwise null/undefined */ function getCodeName(tagName) { - const gitCatOutput = child.spawnSync('git', ['cat-file', '-p ' + tagName], {encoding:'utf8'}).stdout; + const gitCatOutput = child.spawnSync(GIT, ['cat-file', '-p ' + tagName], {encoding:'utf8'}).stdout; const match = gitCatOutput.match(/^.*codename.*$/mg); const tagMessage = match && match[0]; return tagMessage && tagMessage.match(/codename\((.*)\)/)[1]; @@ -36,7 +38,7 @@ function getCodeName(tagName) { * @return {String} The commit SHA */ function getCommitSHA() { - return child.spawnSync('git', ['rev-parse', 'HEAD'], {encoding:'utf8'}).stdout.replace('\n', ''); + return child.spawnSync(GIT, ['rev-parse', 'HEAD'], {encoding:'utf8'}).stdout.replace('\n', ''); } /** @@ -44,7 +46,7 @@ function getCommitSHA() { * @return {String} The build segment of the version */ function getBuild() { - const hash = child.spawnSync('git', ['rev-parse', '--short', 'HEAD'], {encoding:'utf8'}).stdout.replace('\n', ''); + const hash = child.spawnSync(GIT, ['rev-parse', '--short', 'HEAD'], {encoding:'utf8'}).stdout.replace('\n', ''); return 'sha.' + hash; } @@ -53,7 +55,7 @@ function getBuild() { * @return {SemVer} The version or null */ function getTaggedVersion() { - const gitTagResult = child.spawnSync('git', ['describe', '--exact-match'], {encoding:'utf8'}); + const gitTagResult = child.spawnSync(GIT, ['describe', '--exact-match'], {encoding:'utf8'}); if (gitTagResult.status === 0) { const tag = gitTagResult.stdout.trim();