mirror of
https://github.com/nushell/nushell.git
synced 2024-11-30 04:14:17 +01:00
da4d24d082
* Bump to 0.18.2. Move starship external. * Fix failing test
27 lines
699 B
Rust
27 lines
699 B
Rust
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,
|
|
}
|
|
}
|
|
#[cfg(not(feature = "git2"))]
|
|
{
|
|
None
|
|
}
|
|
}
|