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
()
| 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 |
| 227 | pub 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 | } |
no test coverage detected