Package detail

@antongolub/git-root

antongolub1.9kMIT1.5.14

Find the closest .git containing path

git, root, git root, git dir

readme

@antongolub/git-root

Find the closest .git containing path — the git root.

CI Maintainability Test Coverage npm (scoped)

Motivation

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

git rev-parse --show-toplevel

However, if git executable or child_process.exec are not available for some (security?) reasons, it's advisable to use tools like this one. 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-root

Usage

import { gitRoot, gitRootSync } from '@antongolub/git-root'

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

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

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

// `gitRootSync` is an alias for `gitRoot.sync`
const gitRoot4 = gitRootSync()

Alternatives

License

MIT

changelog

1.5.14 (2024-07-06)

Fixes & improvements

  • refactor: remove redundant util.promisify (4e9fb99)

1.5.13 (2023-06-27)

Fixes & improvements

1.5.12 (2023-06-01)

Fixes & improvements

1.5.11 (2023-05-29)

Fixes & improvements

1.5.10 (2023-02-16)

Fixes & improvements

1.5.9 (2023-02-16)

Fixes & improvements

  • refactor: drop find-up dependency (72a9de8)

1.5.8 (2022-11-21)

Fixes & improvements

1.5.7 (2022-05-24)

Bug Fixes

1.5.6 (2021-06-10)

Performance Improvements

1.5.5 (2021-05-25)

Bug Fixes

1.5.4 (2021-05-03)

Bug Fixes

  • package: up deps, fix vuls (3dee833)

1.5.3 (2021-03-28)

Bug Fixes

  • package: up deps, fix vuls (333d51d)

1.5.2 (2021-03-08)

Bug Fixes

1.5.1 (2021-02-07)

Performance Improvements

1.5.0 (2021-02-06)

Features

1.4.0 (2021-01-31)

Bug Fixes

  • package: fix main script ref (a24b8fc)

Features

  • rename gitDir to gitRoot (8143e3c)

1.3.0 (2021-01-31)

Features

1.2.0 (2021-01-31)

Features

  • add gitRoot.sync() alias (efd7f71)

1.1.0 (2021-01-31)

Features

1.0.0 (2021-01-31)

Bug Fixes

Features

  • add initial gitRoot implementation (43a66d2)