diff --git a/src/execGit.js b/src/execGit.js index b07049b40..826ae8df3 100644 --- a/src/execGit.js +++ b/src/execGit.js @@ -2,19 +2,13 @@ const debug = require('debug')('lint-staged:git') const execa = require('execa') -const path = require('path') - -function getAbsolutePath(dir) { - return path.isAbsolute(dir) ? dir : path.resolve(dir) -} module.exports = async function execGit(cmd, options = {}) { - const cwd = options.cwd || process.cwd() debug('Running git command', cmd) try { const { stdout } = await execa('git', [].concat(cmd), { ...options, - cwd: getAbsolutePath(cwd) + cwd: options.cwd || process.cwd() }) return stdout } catch (err) { diff --git a/test/gitWorkflow.spec.js b/test/gitWorkflow.spec.js index 586ecf18a..2ba98bcb6 100644 --- a/test/gitWorkflow.spec.js +++ b/test/gitWorkflow.spec.js @@ -10,26 +10,15 @@ tmp.setGracefulCleanup() describe('gitWorkflow', () => { 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'], { - cwd: path.resolve(process.cwd()) - }) + expect(execa).toHaveBeenCalledWith('git', ['init', 'param'], { cwd }) }) it('should execute git in a given working copy', async () => { - await execGit(['init', 'param'], { cwd: 'test/__fixtures__' }) - expect(execa).toHaveBeenCalledWith('git', ['init', 'param'], { - cwd: path.resolve(process.cwd(), 'test', '__fixtures__') - }) - }) - - it('should work with relative paths', async () => { - await execGit(['init', 'param'], { - cwd: 'test/__fixtures__' - }) - expect(execa).toHaveBeenCalledWith('git', ['init', 'param'], { - cwd: path.resolve(process.cwd(), 'test', '__fixtures__') - }) + const cwd = path.join(process.cwd(), 'test', '__fixtures__') + await execGit(['init', 'param'], { cwd }) + expect(execa).toHaveBeenCalledWith('git', ['init', 'param'], { cwd }) }) })