UNPKG

548 BJavaScriptView Raw
1'use strict'
2
3const debug = require('debug')('lint-staged:git')
4const execa = require('execa')
5const path = require('path')
6
7function getAbsolutePath(dir) {
8 return path.isAbsolute(dir) ? dir : path.resolve(dir)
9}
10
11module.exports = async function execGit(cmd, options = {}) {
12 const cwd = options.cwd || process.cwd()
13 debug('Running git command', cmd)
14 try {
15 const { stdout } = await execa('git', [].concat(cmd), {
16 ...options,
17 cwd: getAbsolutePath(cwd)
18 })
19 return stdout
20 } catch (err) {
21 throw new Error(err)
22 }
23}