MCPcopy Create free account
hub / github.com/elastio/devx / locate_project_root

Function locate_project_root

devx-pre-commit/src/lib.rs:227–233  ·  view source on GitHub ↗

Searches for a project root dir, which is a directory that contains a `.git` dir as its direct child (it should also be the root of the project's `Rust` crate or [cargo workspace][cargo-workspace]). It uses the following steps: 1. Use the value of [`$GIT_DIR`][git-dir] env variable if it is present. (This variable is set by git when it invokes current process as a hook). 2. Fallback to the output

()

Source from the content-addressed store, hash-verified

225/// [git-rev-parse]: https://git-scm.com/docs/git-rev-parse#Documentation/git-rev-parse.txt---show-toplevel
226/// [cargo-workspace]: https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html
227pub fn locate_project_root() -> Result<PathBuf> {
228 Ok(env::var("GIT_DIR").map(Into::into).or_else(|_| {
229 cmd!("git", "rev-parse", "--show-toplevel")
230 .read()
231 .map(|it| it.trim_end().into())
232 })?)
233}

Callers 1

project_root_dirFunction · 0.85

Calls 1

readMethod · 0.80

Tested by

no test coverage detected