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(git): Use resolveGitDir to resolve to .git for git commands #518

Merged
merged 1 commit into from Oct 29, 2018
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
3 changes: 2 additions & 1 deletion src/gitWorkflow.js
Expand Up @@ -5,6 +5,7 @@ const execa = require('execa')
const gStatus = require('g-status')
const del = require('del')
const debug = require('debug')('lint-staged:git')
const resolveGitDir = require('./resolveGitDir')

let workingCopyTree = null
let indexTree = null
Expand All @@ -15,7 +16,7 @@ function getAbsolutePath(dir) {
}

async function execGit(cmd, options) {
const cwd = options && options.cwd ? options.cwd : process.cwd()
const cwd = options && options.cwd ? options.cwd : resolveGitDir()
debug('Running git command', cmd)
try {
const { stdout } = await execa('git', [].concat(cmd), {
Expand Down
10 changes: 5 additions & 5 deletions test/gitWorkflow.spec.js
Expand Up @@ -3,28 +3,28 @@
import path from 'path'
import tmp from 'tmp'
import execa from 'execa'
import gitflow from '../src/gitWorkflow'
import { execGit } from '../src/gitWorkflow'

tmp.setGracefulCleanup()

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

it('should execute git in a given working copy', async () => {
await gitflow.execGit(['init', 'param'], { cwd: 'test/__fixtures__' })
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 gitflow.execGit(['init', 'param'], {
await execGit(['init', 'param'], {
cwd: 'test/__fixtures__'
})
expect(execa).toHaveBeenCalledWith('git', ['init', 'param'], {
Expand Down