Skip to content

Commit

Permalink
test: add test for resolveGitDir behaviour outside a git directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Iiro Jäppinen authored and okonet committed Jun 6, 2019
1 parent c87671f commit ed9e586
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/resolveGitDir.js
Expand Up @@ -4,9 +4,9 @@ const execGit = require('./execGit')
const path = require('path')
const printErrors = require('./printErrors')

module.exports = async function resolveGitDir() {
module.exports = async function resolveGitDir(options) {
try {
const gitDir = await execGit(['rev-parse', '--show-toplevel'])
const gitDir = await execGit(['rev-parse', '--show-toplevel'], options)
return path.normalize(gitDir)
} catch (error) {
printErrors(error)
Expand Down
5 changes: 5 additions & 0 deletions test/resolveGitDir.spec.js
Expand Up @@ -20,4 +20,9 @@ describe('resolveGitDir', () => {
expect(path.resolve(await resolveGitDir())).toEqual(expected)
process.cwd = processCwdBkp
})

it('should return null when not in a git directory', async () => {
const gitDir = await resolveGitDir({ cwd: '/' }) // assume root is not a git directory
expect(gitDir).toEqual(null)
})
})

0 comments on commit ed9e586

Please sign in to comment.