UNPKG

773 BJavaScriptView Raw
1import debug from 'debug'
2import { execa } from 'execa'
3
4const debugLog = debug('lint-staged:execGit')
5
6/**
7 * Explicitly never recurse commands into submodules, overriding local/global configuration.
8 * @see https://git-scm.com/docs/git-config#Documentation/git-config.txt-submodulerecurse
9 */
10const NO_SUBMODULE_RECURSE = ['-c', 'submodule.recurse=false']
11
12// exported for tests
13export const GIT_GLOBAL_OPTIONS = [...NO_SUBMODULE_RECURSE]
14
15export 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}