Skip to content

Commit

Permalink
feat: default to git binary in environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kormide authored and devversion committed Sep 13, 2022
1 parent 859ac83 commit acb4f75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion git/services/getPreviousVersions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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 [];
}
Expand Down
10 changes: 6 additions & 4 deletions git/services/versionInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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];
Expand All @@ -36,15 +38,15 @@ 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', '');
}

/**
* Compute a build segment for the version, from the Jenkins build number and current commit SHA
* @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;
}

Expand All @@ -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();
Expand Down

0 comments on commit acb4f75

Please sign in to comment.