1 | 'use strict'
|
2 |
|
3 | const debug = require('debug')('lint-staged:git')
|
4 | const execa = require('execa')
|
5 | const path = require('path')
|
6 |
|
7 | function getAbsolutePath(dir) {
|
8 | return path.isAbsolute(dir) ? dir : path.resolve(dir)
|
9 | }
|
10 |
|
11 | module.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 | }
|