find-gitdir
v1.0.0
Published
Find .git directory with support of submodules and --separate-git-dir
Downloads
1,090
Maintainers
Readme
find-gitdir
Find .git
directory with support of submodules and --separate-git-dir
.
Usage
const gitdir = require('find-gitdir')
Let's say we have a git repository at /example
and that this is our working directory. Its gitdir will commonly be at /example/.git
.
await gitdir() // /example/.git
Let's also say we have a git submodule at ./beep
. Then find-gitdir
will find a symbolic link at ./beep/.git
pointing to the gitdir ../.git/modules/beep
:
await gitdir('./beep') // /example/.git/modules/beep
By default find-gitdir
does not look in parent directories. It can be enabled:
await gitdir('./node_modules/find-gitdir') // null
await gitdir('./node_modules/find-gitdir', true) // /example/.git
API
gitdir([cwd][, roam][, callback])
Yields an absolute path to a .git
directory or null
if not found, given working directory cwd
which defaults to process.cwd()
. Set roam
to true to enable looking in parent directories. If no callback if provided, a promise is returned.
gitdir.sync([cwd][, roam])
Synchronous variant. Returns an absolute path or null
.
Install
With npm do:
npm install find-gitdir
License
MIT © Vincent Weevers