Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: run all git commands with submodule.recurse=false #888

Merged
merged 1 commit into from Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/execGit.js
Expand Up @@ -3,10 +3,18 @@
const debug = require('debug')('lint-staged:git')
const execa = require('execa')

/**
* Explicitly never recurse commands into submodules, overriding local/global configuration.
* @see https://git-scm.com/docs/git-config#Documentation/git-config.txt-submodulerecurse
*/
const NO_SUBMODULE_RECURSE = ['-c', 'submodule.recurse=false']

const GIT_GLOBAL_OPTIONS = [...NO_SUBMODULE_RECURSE]

module.exports = async function execGit(cmd, options = {}) {
debug('Running git command', cmd)
try {
const { stdout } = await execa('git', [].concat(cmd), {
const { stdout } = await execa('git', GIT_GLOBAL_OPTIONS.concat(cmd), {
...options,
all: true,
cwd: options.cwd || process.cwd(),
Expand All @@ -16,3 +24,6 @@ module.exports = async function execGit(cmd, options = {}) {
throw new Error(all)
}
}

// exported for tests
module.exports.GIT_GLOBAL_OPTIONS = GIT_GLOBAL_OPTIONS
22 changes: 19 additions & 3 deletions test/execGit.spec.js
@@ -1,17 +1,33 @@
import path from 'path'
import execa from 'execa'
import execGit from '../lib/execGit'

import execGit, { GIT_GLOBAL_OPTIONS } from '../lib/execGit'

test('GIT_GLOBAL_OPTIONS', () => {
expect(GIT_GLOBAL_OPTIONS).toMatchInlineSnapshot(`
Array [
"-c",
"submodule.recurse=false",
]
`)
})

describe('execGit', () => {
it('should execute git in process.cwd if working copy is not specified', async () => {
const cwd = process.cwd()
await execGit(['init', 'param'])
expect(execa).toHaveBeenCalledWith('git', ['init', 'param'], { all: true, cwd })
expect(execa).toHaveBeenCalledWith('git', [...GIT_GLOBAL_OPTIONS, 'init', 'param'], {
all: true,
cwd,
})
})

it('should execute git in a given working copy', async () => {
const cwd = path.join(process.cwd(), 'test', '__fixtures__')
await execGit(['init', 'param'], { cwd })
expect(execa).toHaveBeenCalledWith('git', ['init', 'param'], { all: true, cwd })
expect(execa).toHaveBeenCalledWith('git', [...GIT_GLOBAL_OPTIONS, 'init', 'param'], {
all: true,
cwd,
})
})
})