1.3.0 • Published 3 years ago

@antongolub/git-dir v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@antongolub/git-dir

Find the closest .git containing path.

CI David Maintainability Test Coverage

Motivation

It's known for certain the best way to find git root:

git rev-parse --show-toplevel

It makes sense to use this tool only if git executable or child_process.exec are not available for some (security?) reasons. Inspired by pkg-dir.

Features

  • Searches for .git up the dir tree
  • Handles gitdir: </some/path.git> redirects
  • TS and Flow typings out of box
  • Sync/async methods

Install

yarn add @antongolub/git-dir

Usage

import { gitDir, gitDirSync } from '@antongolub/git-dir'

// async
const gitRoot1 = await gitDir('/optional/cwd/path/')

// sync
const gitRoot2 = gitDir('/defaults/to/process/cwd/', true)

// sync too
const gitRoot3 = gitDir.sync()

// `gitDirSync` is alias for `gitDir.sync`
const gitRoot4 = gitDirSync()

Alternatives

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago