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

27 lines
699 B
Rust
Raw Normal View History

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