Skip to content

vweevers/find-gitdir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

find-gitdir

Find .git directory with support of submodules, --separate-git-dir and linked worktrees.

npm status node Test JavaScript Style Guide

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', { roam: true }) // /example/.git

API

gitdir([cwd][, options][, callback])

Yields an absolute path to a .git directory or null if not found, given working directory cwd which defaults to process.cwd(). If no callback if provided, a promise is returned. Options:

  • roam (boolean, default false): enable looking in parent directories
  • common (boolean, default false): if cwd is a linked worktree then return the gitdir of the main worktree (a.k.a. $GIT_COMMON_DIR) instead of the gitdir of the linked worktree. This can be useful if you need non-worktree files like config.

If options is a boolean, it is interpreted as options.roam for backwards compatibility.

gitdir.sync([cwd][, options])

Synchronous variant. Returns an absolute path or null.

Install

With npm do:

npm install find-gitdir

License

MIT © Vincent Weevers

About

Find .git directory with support of submodules and --separate-git-dir.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •