Adds the options `extends`, which can be defined via configuration file or CLI arguments to a single path or an array of paths of shareable configuration. A shareable configuration is a file or a module that can be loaded with `require`. Options is defined by merging in the following order of priority: - CLI/API - Configuration file - Shareable configuration (from right to left) Options set in a shareable configuration can be unset by setting it to `null` or `undefined` in the main configuration file. If a default value applies to this property it will be used.
92 lines
2.6 KiB
JavaScript
92 lines
2.6 KiB
JavaScript
const execa = require('execa');
|
|
const debug = require('debug')('semantic-release:get-version-head');
|
|
const {debugShell} = require('./debug');
|
|
|
|
/**
|
|
* Get the commit sha for a given tag.
|
|
*
|
|
* @param {string} tagName Tag name for which to retrieve the commit sha.
|
|
*
|
|
* @return {string} The commit sha of the tag in parameter or `null`.
|
|
*/
|
|
async function gitTagHead(tagName) {
|
|
try {
|
|
const shell = await execa('git', ['rev-list', '-1', tagName]);
|
|
debugShell('Get git tag head', shell, debug);
|
|
return shell.stdout;
|
|
} catch (err) {
|
|
debug(err);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the tag associated with a commit sha.
|
|
*
|
|
* @param {string} gitHead The commit sha for which to retrieve the associated tag.
|
|
*
|
|
* @return {string} The tag associatedwith the sha in parameter or `null`.
|
|
*/
|
|
async function gitCommitTag(gitHead) {
|
|
try {
|
|
const shell = await execa('git', ['describe', '--tags', '--exact-match', gitHead]);
|
|
debugShell('Get git commit tag', shell, debug);
|
|
return shell.stdout;
|
|
} catch (err) {
|
|
debug(err);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Verify if the commit `sha` is in the direct history of the current branch.
|
|
*
|
|
* @param {string} sha The sha of the commit to look for.
|
|
*
|
|
* @return {boolean} `true` if the commit `sha` is in the history of the current branch, `false` otherwise.
|
|
*/
|
|
async function isCommitInHistory(sha) {
|
|
const shell = await execa('git', ['merge-base', '--is-ancestor', sha, 'HEAD'], {reject: false});
|
|
debugShell('Check if commit is in history', shell, debug);
|
|
return shell.code === 0;
|
|
}
|
|
|
|
/**
|
|
* Unshallow the git repository (retriving every commits and tags).
|
|
*/
|
|
async function unshallow() {
|
|
await execa('git', ['fetch', '--unshallow', '--tags'], {reject: false});
|
|
}
|
|
|
|
/**
|
|
* @return {string} the sha of the HEAD commit.
|
|
*/
|
|
async function gitHead() {
|
|
try {
|
|
const shell = await execa('git', ['rev-parse', 'HEAD']);
|
|
debugShell('Get git head', shell, debug);
|
|
return shell.stdout;
|
|
} catch (err) {
|
|
debug(err);
|
|
throw new Error(err.stderr);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return {string|undefined} The value of the remote git URL.
|
|
*/
|
|
async function repoUrl() {
|
|
return (await execa.stdout('git', ['remote', 'get-url', 'origin'], {reject: false})) || undefined;
|
|
}
|
|
|
|
/**
|
|
* @return {Boolean} `true` if the current working directory is in a git repository, `false` otherwise.
|
|
*/
|
|
async function isGitRepo() {
|
|
const shell = await execa('git', ['rev-parse', '--git-dir'], {reject: false});
|
|
debugShell('Check if the current working directory is a git repository', shell, debug);
|
|
return shell.code === 0;
|
|
}
|
|
|
|
module.exports = {gitTagHead, gitCommitTag, isCommitInHistory, unshallow, gitHead, repoUrl, isGitRepo};
|