From 890d141b9d4563792b64f177f895dd013dea2006 Mon Sep 17 00:00:00 2001 From: MasterGordon Date: Thu, 15 Aug 2024 17:45:57 +0200 Subject: [PATCH] fixed sync relating to current branches origin --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/prompt_parts/branch_name.rs | 9 +++++++-- src/prompt_parts/branch_sync.rs | 4 +++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 77b2790..de685cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,7 +35,7 @@ checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" [[package]] name = "fast-git-prompt" -version = "0.2.0" +version = "0.2.1" dependencies = [ "git2", "regex", diff --git a/Cargo.toml b/Cargo.toml index ea6dcfa..85ff288 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fast-git-prompt" -version = "0.2.0" +version = "0.2.1" description = "A fast git prompt for zsh and bash." license = "MIT" repository = "https://github.com/MasterGordon/fast-git-prompt" diff --git a/src/prompt_parts/branch_name.rs b/src/prompt_parts/branch_name.rs index 1251d09..c45938a 100644 --- a/src/prompt_parts/branch_name.rs +++ b/src/prompt_parts/branch_name.rs @@ -11,10 +11,15 @@ pub struct BranchName { impl RenderablePromptPart for BranchName { fn render(self, repo: &Repository) -> Option { - let head = match repo.head() { + let head_o = match repo.head() { Ok(r) => Some(r), Err(_) => None, - }?; + }; + if head_o.is_none() { + return Some("HEADLESS".to_string()); + } + let head = head_o?; + let name = head.name()?; let last = name.split('/').last()?; let head_commit = head.peel_to_commit().unwrap(); diff --git a/src/prompt_parts/branch_sync.rs b/src/prompt_parts/branch_sync.rs index 1cb0b06..2e64f0a 100644 --- a/src/prompt_parts/branch_sync.rs +++ b/src/prompt_parts/branch_sync.rs @@ -14,8 +14,10 @@ impl RenderablePromptPart for BranchSync { fn render(self, repo: &Repository) -> Option { let head = repo.head().ok()?; let head_oid = head.target()?; + let name = head.name()?; + let last = name.split('/').last()?; let remote = repo - .find_branch("origin/main", git2::BranchType::Remote) + .find_branch(&format!("origin/{}", last), git2::BranchType::Remote) .ok()?; let remote_oid = remote.get().target()?; let (ahead, behind) = repo.graph_ahead_behind(head_oid, remote_oid).ok()?;