UNPKG

506 BJavaScriptView Raw
1'use strict'
2
3const execGit = require('./execGit')
4const path = require('path')
5
6module.exports = async function resolveGitDir(options) {
7 try {
8 // git cli uses GIT_DIR to fast track its response however it might be set to a different path
9 // depending on where the caller initiated this from, hence clear GIT_DIR
10 delete process.env.GIT_DIR
11 const gitDir = await execGit(['rev-parse', '--show-toplevel'], options)
12 return path.normalize(gitDir)
13 } catch (error) {
14 return null
15 }
16}