2019-06-01 23:11:28 +02:00
|
|
|
pub fn current_branch() -> Option<String> {
|
2020-08-13 21:02:45 +02:00
|
|
|
#[cfg(feature = "git2")]
|
|
|
|
{
|
|
|
|
use git2::{Repository, RepositoryOpenFlags};
|
|
|
|
use std::ffi::OsString;
|
2020-07-18 03:59:23 +02:00
|
|
|
|
2020-08-13 21:02:45 +02:00
|
|
|
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,
|
|
|
|
},
|
2020-07-18 03:59:23 +02:00
|
|
|
_ => None,
|
2020-06-25 07:44:55 +02:00
|
|
|
}
|
2020-07-18 03:59:23 +02:00
|
|
|
}
|
2020-08-13 21:02:45 +02:00
|
|
|
_ => None,
|
2019-08-26 20:19:05 +02:00
|
|
|
}
|
2020-08-13 21:02:45 +02:00
|
|
|
}
|
|
|
|
#[cfg(not(feature = "git2"))]
|
|
|
|
{
|
2020-06-25 07:44:55 +02:00
|
|
|
None
|
2019-06-01 23:11:28 +02:00
|
|
|
}
|
|
|
|
}
|