From bcf9bac9349a90b586f62c07aad77e83b1c117c3 Mon Sep 17 00:00:00 2001 From: extrawurst Date: Mon, 27 Nov 2023 16:21:04 +0100 Subject: [PATCH] simplify implementation --- asyncgit/src/sync/branch/mod.rs | 17 +++++++---------- 1 file 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 { 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())?) } ///