UNPKG

git-command-helper

Version:
28 lines (24 loc) 822 B
// git-command-helper 2.1.0 by Dimas Lanjaka <dimaslanjaka@gmail.com> (https://www.webmanajemen.com) 'use strict'; var sbgUtility = require('sbg-utility'); var path = require('upath'); require('bluebird'); require('cross-spawn'); var spawnAsync = require('../dependencies/@expo/spawn-async/build/spawnAsync.js'); require('lodash'); require('stream'); /** * get root directory of local repository * * see {@link https://stackoverflow.com/a/957978} * @returns */ async function getGithubRootDir(opt = {}) { if (!opt.cwd) opt.cwd = process.cwd(); try { const result = await spawnAsync("git", ["rev-parse", "--show-toplevel"], opt); return path.toUnix(sbgUtility.trueCasePathSync(result.stdout.trim())); } catch (err) { if (opt.throwable) throw err; } } exports.getGithubRootDir = getGithubRootDir;