UNPKG

818 BJavaScriptView Raw
1'use strict'
2
3const debug = require('debug')('lint-staged:git')
4const execa = require('execa')
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
12const GIT_GLOBAL_OPTIONS = [...NO_SUBMODULE_RECURSE]
13
14module.exports = async function execGit(cmd, options = {}) {
15 debug('Running git command', cmd)
16 try {
17 const { stdout } = await execa('git', GIT_GLOBAL_OPTIONS.concat(cmd), {
18 ...options,
19 all: true,
20 cwd: options.cwd || process.cwd(),
21 })
22 return stdout
23 } catch ({ all }) {
24 throw new Error(all)
25 }
26}
27
28// exported for tests
29module.exports.GIT_GLOBAL_OPTIONS = GIT_GLOBAL_OPTIONS