@antongolub/git-root (英语)
寻找最接近的包含路径的.git – git 根.
动机
以找到 gi根的最好方法而出名:
git rev-parse --show-toplevel
然而,如果 git 可执行文件或 child_process.exec 由于一些(安全原因?)原因不能使用,使用这种工具是可取的.
灵感来自 pkg 迪尔。 。 。 .
特征
- 搜索
.git在目录树上 - 处理
gitdir: </some/path.git>重定向 - TS 和流打出框
- 同步/同步方法
安装
yarn add @antongolub/git-root
使用量
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()