Created
March 14, 2019 20:33
-
-
Save autarch/8071923edbb45fdb6e66f3feae29e236 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] | |
extern crate failure_derive; | |
... | |
#[derive(Debug, Fail)] | |
enum RuntimeError { | |
CannotFindRoot { cwd: PathBuf }, | |
} | |
impl fmt::Display for RuntimeError { | |
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
match self { | |
RuntimeError::CannotFindRoot { cwd: cwd } => write!( | |
f, | |
"Could not find a VCS checkout root starting from {}", | |
cwd.to_string_lossy() | |
), | |
} | |
} | |
} | |
... | |
fn set_root(&mut self) -> Result<(), Error> { | |
let cwd = env::current_dir()?; | |
let mut root = PathBuf::new(); | |
for anc in cwd.ancestors() { | |
if self.is_checkout_root(&anc) { | |
root.push(anc); | |
self.root = Some(root); | |
return Ok(()); | |
} | |
} | |
Err(RuntimeError::CannotFindRoot { cwd: cwd }) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment