nushell/crates/nu-cli/src/git.rs
Jason Gedge b2c5af457e
Move most of the root package into a subcrate. (#1445)
This improves incremental build time when working on what was previously
the root package. For example, previously all plugins would be rebuilt
with a change to `src/commands/classified/external.rs`, but now only
`nu-cli` will have to be rebuilt (and anything that depends on it).
2020-03-04 13:58:20 -05:00

22 lines
570 B
Rust

#![cfg(not(feature = "starship-prompt"))]
use git2::{Repository, RepositoryOpenFlags};
use std::ffi::OsString;
pub fn current_branch() -> Option<String> {
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,
}
}