Created
November 20, 2019 23:16
-
-
Save vhata/b5c27796fb0438315fdd76ac937b69f4 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
use std::process::Command; | |
fn main() -> std::io::Result<()> { | |
let args: Vec<std::ffi::OsString> = std::env::args_os().collect(); | |
if args.len() > 1 { | |
eprintln!("no arguments allowed"); | |
std::process::exit(1); | |
} | |
let mut path = std::env::current_dir()?; | |
loop { | |
let mut hg = path.clone(); | |
hg.push(".hg"); | |
if hg.is_dir() { | |
std::process::exit( | |
Command::new("hg") | |
.arg("status") | |
.spawn()? | |
.wait()? | |
.code() | |
.unwrap(), | |
); | |
} | |
let mut git = path.clone(); | |
git.push(".git"); | |
if git.is_dir() { | |
std::process::exit( | |
Command::new("git") | |
.arg("status") | |
.spawn()? | |
.wait()? | |
.code() | |
.unwrap(), | |
); | |
} | |
if !path.pop() { | |
eprintln!("not inside a checkout"); | |
std::process::exit(1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment