fixed sync relating to current branches origin

This commit is contained in:
MasterGordon 2024-08-15 17:45:57 +02:00
parent 5b6d1e3795
commit 890d141b9d
4 changed files with 12 additions and 5 deletions

2
Cargo.lock generated
View File

@ -35,7 +35,7 @@ checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125"
[[package]] [[package]]
name = "fast-git-prompt" name = "fast-git-prompt"
version = "0.2.0" version = "0.2.1"
dependencies = [ dependencies = [
"git2", "git2",
"regex", "regex",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "fast-git-prompt" name = "fast-git-prompt"
version = "0.2.0" version = "0.2.1"
description = "A fast git prompt for zsh and bash." description = "A fast git prompt for zsh and bash."
license = "MIT" license = "MIT"
repository = "https://github.com/MasterGordon/fast-git-prompt" repository = "https://github.com/MasterGordon/fast-git-prompt"

View File

@ -11,10 +11,15 @@ pub struct BranchName {
impl RenderablePromptPart for BranchName { impl RenderablePromptPart for BranchName {
fn render(self, repo: &Repository) -> Option<String> { fn render(self, repo: &Repository) -> Option<String> {
let head = match repo.head() { let head_o = match repo.head() {
Ok(r) => Some(r), Ok(r) => Some(r),
Err(_) => None, Err(_) => None,
}?; };
if head_o.is_none() {
return Some("HEADLESS".to_string());
}
let head = head_o?;
let name = head.name()?; let name = head.name()?;
let last = name.split('/').last()?; let last = name.split('/').last()?;
let head_commit = head.peel_to_commit().unwrap(); let head_commit = head.peel_to_commit().unwrap();

View File

@ -14,8 +14,10 @@ impl RenderablePromptPart for BranchSync {
fn render(self, repo: &Repository) -> Option<String> { fn render(self, repo: &Repository) -> Option<String> {
let head = repo.head().ok()?; let head = repo.head().ok()?;
let head_oid = head.target()?; let head_oid = head.target()?;
let name = head.name()?;
let last = name.split('/').last()?;
let remote = repo let remote = repo
.find_branch("origin/main", git2::BranchType::Remote) .find_branch(&format!("origin/{}", last), git2::BranchType::Remote)
.ok()?; .ok()?;
let remote_oid = remote.get().target()?; let remote_oid = remote.get().target()?;
let (ahead, behind) = repo.graph_ahead_behind(head_oid, remote_oid).ok()?; let (ahead, behind) = repo.graph_ahead_behind(head_oid, remote_oid).ok()?;