1 | import debug from 'debug'
|
2 | import execa from 'execa'
|
3 |
|
4 | const debugLog = debug('lint-staged:execGit')
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | const NO_SUBMODULE_RECURSE = ['-c', 'submodule.recurse=false']
|
11 |
|
12 |
|
13 | export const GIT_GLOBAL_OPTIONS = [...NO_SUBMODULE_RECURSE]
|
14 |
|
15 | export const execGit = async (cmd, options = {}) => {
|
16 | debugLog('Running git command', cmd)
|
17 | try {
|
18 | const { stdout } = await execa('git', GIT_GLOBAL_OPTIONS.concat(cmd), {
|
19 | ...options,
|
20 | all: true,
|
21 | cwd: options.cwd || process.cwd(),
|
22 | })
|
23 | return stdout
|
24 | } catch ({ all }) {
|
25 | throw new Error(all)
|
26 | }
|
27 | }
|