blob: 9fdcc27a095bdedecfad32789f7c554d89d2727d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
use anyhow::{bail, Result};
use std::{env, path::PathBuf};
pub fn find_root() -> Result<PathBuf> {
let mut location = env::current_dir()?;
let mut found_root = false;
for loc in location.ancestors() {
let mut loc = loc.join(".git");
if loc.exists() {
loc.pop();
found_root = true;
location = loc.canonicalize()?;
break;
}
}
if found_root {
Ok(location)
} else {
bail!("Unable to find a valid git repo");
}
}
|