Don’t show upstream if commit is local branch head

This commit is contained in:
Christoph Rüßler 2023-04-08 20:29:59 +02:00 committed by extrawurst
parent 3af256c75a
commit 2554f04ace
3 changed files with 51 additions and 6 deletions

View File

@ -55,9 +55,18 @@ pub struct LocalBranch {
/// ///
pub has_upstream: bool, pub has_upstream: bool,
/// ///
pub upstream: Option<UpstreamBranch>,
///
pub remote: Option<String>, pub remote: Option<String>,
} }
///
#[derive(Clone, Debug)]
pub struct UpstreamBranch {
///
pub reference: String,
}
/// ///
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct RemoteBranch { pub struct RemoteBranch {
@ -154,10 +163,18 @@ pub fn get_branches_info(
let name_bytes = branch.name_bytes()?; let name_bytes = branch.name_bytes()?;
let upstream_branch =
upstream.ok().and_then(|upstream| {
bytes2string(upstream.get().name_bytes())
.ok()
.map(|reference| UpstreamBranch { reference })
});
let details = if local { let details = if local {
BranchDetails::Local(LocalBranch { BranchDetails::Local(LocalBranch {
is_head: branch.is_head(), is_head: branch.is_head(),
has_upstream: upstream.is_ok(), has_upstream: upstream_branch.is_some(),
upstream: upstream_branch,
remote, remote,
}) })
} else { } else {

View File

@ -41,7 +41,7 @@ pub use branch::{
merge_commit::merge_upstream_commit, merge_commit::merge_upstream_commit,
merge_ff::branch_merge_upstream_fastforward, merge_ff::branch_merge_upstream_fastforward,
merge_rebase::merge_upstream_rebase, rename::rename_branch, merge_rebase::merge_upstream_rebase, rename::rename_branch,
validate_branch_name, BranchCompare, BranchInfo, validate_branch_name, BranchCompare, BranchDetails, BranchInfo,
}; };
pub use commit::{amend, commit, tag_commit}; pub use commit::{amend, commit, tag_commit};
pub use commit_details::{ pub use commit_details::{

View File

@ -13,7 +13,8 @@ use crate::{
}; };
use anyhow::Result; use anyhow::Result;
use asyncgit::sync::{ use asyncgit::sync::{
checkout_commit, BranchInfo, CommitId, RepoPathRef, Tags, checkout_commit, BranchDetails, BranchInfo, CommitId,
RepoPathRef, Tags,
}; };
use chrono::{DateTime, Local}; use chrono::{DateTime, Local};
use crossterm::event::Event; use crossterm::event::Event;
@ -430,13 +431,40 @@ impl CommitList {
let remote_branches = self let remote_branches = self
.remote_branches .remote_branches
.get(&e.id) .get(&e.id)
.map(|remote_branches| { .and_then(|remote_branches| {
remote_branches let filtered_branches: Vec<_> = remote_branches
.iter() .iter()
.filter(|remote_branch| {
self.local_branches
.get(&e.id)
.map_or(true, |local_branch| {
local_branch.iter().any(
|local_branch| {
let has_corresponding_local_branch = match &local_branch.details {
BranchDetails::Local(details) =>
details
.upstream
.as_ref()
.map_or(false, |upstream| upstream.reference == remote_branch.reference),
BranchDetails::Remote(_) =>
false,
};
!has_corresponding_local_branch
},
)
})
})
.map(|remote_branch| { .map(|remote_branch| {
format!("[{0}]", remote_branch.name) format!("[{0}]", remote_branch.name)
}) })
.join(" ") .collect();
if filtered_branches.is_empty() {
None
} else {
Some(filtered_branches.join(" "))
}
}); });
let marked = if any_marked { let marked = if any_marked {