nushell/crates/nu-cli/src/git.rs

22 lines
570 B
Rust
Raw Normal View History

#![cfg(not(feature = "starship-prompt"))]
2019-06-01 23:38:28 +00:00
use git2::{Repository, RepositoryOpenFlags};
use std::ffi::OsString;
2019-06-01 21:11:28 +00:00
pub fn current_branch() -> Option<String> {
2019-06-01 23:38:28 +00:00
let v: Vec<OsString> = vec![];
match Repository::open_ext(".", RepositoryOpenFlags::empty(), v) {
2019-06-01 21:11:28 +00:00
Ok(repo) => {
let r = repo.head();
match r {
2019-08-26 18:19:05 +00:00
Ok(r) => match r.shorthand() {
Some(s) => Some(s.to_string()),
None => None,
2019-06-01 21:11:28 +00:00
},
2019-08-26 18:19:05 +00:00
_ => None,
2019-06-01 21:11:28 +00:00
}
2019-08-26 18:19:05 +00:00
}
_ => None,
2019-06-01 21:11:28 +00:00
}
}