summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorextrawurst <mail@rusticorn.com>2023-11-27 16:21:04 +0100
committerextrawurst <mail@rusticorn.com>2023-11-27 16:21:04 +0100
commitbcf9bac9349a90b586f62c07aad77e83b1c117c3 (patch)
tree07a295886b5fd22b9ebcd0f52569261110aea56e
parentd576405223ff463d05e4840eeac0491387e05ee9 (diff)
simplify implementation
-rw-r--r--asyncgit/src/sync/branch/mod.rs17
1 files changed, 7 insertions, 10 deletions
diff --git a/asyncgit/src/sync/branch/mod.rs b/asyncgit/src/sync/branch/mod.rs
index 98da9b68..cd6883fd 100644
--- a/asyncgit/src/sync/branch/mod.rs
+++ b/asyncgit/src/sync/branch/mod.rs
@@ -33,18 +33,15 @@ pub(crate) fn get_branch_name_repo(
) -> Result<String> {
scope_time!("get_branch_name_repo");
- let iter = repo.branches(None)?;
-
- for b in iter {
- let b = b?;
-
- if b.0.is_head() {
- let name = b.0.name()?.unwrap_or("");
- return Ok(name.into());
+ let head_ref = repo.head().map_err(|e| {
+ if e.code() == git2::ErrorCode::UnbornBranch {
+ Error::NoHead
+ } else {
+ e.into()
}
- }
+ })?;
- Err(Error::NoHead)
+ Ok(bytes2string(head_ref.shorthand_bytes())?)
}
///