/** * Gets the current git branch. * * @param {GetCurrentGitBranchOptions} [opts] Custom options. * * @return {string} The name of the current branch. */ export function getCurrentGitBranch(opts?: GetCurrentGitBranchOptions): string { return toStringSafe( asArray( spawn( 'git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: getCWD(opts), stdio: null, } ).output ).join('') ).trim(); }
/** * Checks if a git repository has uncommited changes or not. * * @param {HasGitChangesOptions} [opts] Custom options. * * @return {boolean} Has uncomitted changes or not. */ export function hasGitChanges(opts?: HasGitChangesOptions): boolean { if (_.isNil(opts)) { opts = {} as any; } return asArray( spawn( 'git', ['status', '-s'], { cwd: getCWD(opts), stdio: null, } ).output ).map((x) => { return toStringSafe(x) .split('\n'); }).reduce((x, y) => { return x.concat(y); }, []).filter(x => '' !== x.trim()) .length > 0; }
stdio: null, ).output ).map((x) => { return toStringSafe(x)
spawn('git', ['remote', 'get-url', remote], { stdio: null }).output ).map(x => toStringSafe(x).trim()) .filter(x => '' !== x)
stdio: null, ).output ).map((x) => { return toStringSafe(x)
/** * Lists the IDs of all running docker containers. * * @param {GetRunningDockerContainers} [opts] Custom options. * * @return {string[]} The list of running docker container IDs. */ export function getRunningDockerContainers(opts?: GetRunningDockerContainers): string[] { if (_.isNil(opts)) { opts = {} as any; } return asArray( spawn( 'docker', ['ps', '--format', '{{.ID}}'], { cwd: getCWD(opts), stdio: null, } ).output ).map((x) => { return toStringSafe(x) .split('\n'); }).reduce((x, y) => { return x.concat(y); }, []).map(b => b.trim()) .filter(b => '' !== b); }