Skip to content

Commit 2554f04

Browse files
cruesslerextrawurst
authored andcommitted
Don’t show upstream if commit is local branch head
1 parent 3af256c commit 2554f04

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

asyncgit/src/sync/branch/mod.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,18 @@ pub struct LocalBranch {
5555
///
5656
pub has_upstream: bool,
5757
///
58+
pub upstream: Option<UpstreamBranch>,
59+
///
5860
pub remote: Option<String>,
5961
}
6062

63+
///
64+
#[derive(Clone, Debug)]
65+
pub struct UpstreamBranch {
66+
///
67+
pub reference: String,
68+
}
69+
6170
///
6271
#[derive(Clone, Debug)]
6372
pub struct RemoteBranch {
@@ -154,10 +163,18 @@ pub fn get_branches_info(
154163

155164
let name_bytes = branch.name_bytes()?;
156165

166+
let upstream_branch =
167+
upstream.ok().and_then(|upstream| {
168+
bytes2string(upstream.get().name_bytes())
169+
.ok()
170+
.map(|reference| UpstreamBranch { reference })
171+
});
172+
157173
let details = if local {
158174
BranchDetails::Local(LocalBranch {
159175
is_head: branch.is_head(),
160-
has_upstream: upstream.is_ok(),
176+
has_upstream: upstream_branch.is_some(),
177+
upstream: upstream_branch,
161178
remote,
162179
})
163180
} else {

asyncgit/src/sync/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub use branch::{
4141
merge_commit::merge_upstream_commit,
4242
merge_ff::branch_merge_upstream_fastforward,
4343
merge_rebase::merge_upstream_rebase, rename::rename_branch,
44-
validate_branch_name, BranchCompare, BranchInfo,
44+
validate_branch_name, BranchCompare, BranchDetails, BranchInfo,
4545
};
4646
pub use commit::{amend, commit, tag_commit};
4747
pub use commit_details::{

src/components/commitlist.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use crate::{
1313
};
1414
use anyhow::Result;
1515
use asyncgit::sync::{
16-
checkout_commit, BranchInfo, CommitId, RepoPathRef, Tags,
16+
checkout_commit, BranchDetails, BranchInfo, CommitId,
17+
RepoPathRef, Tags,
1718
};
1819
use chrono::{DateTime, Local};
1920
use crossterm::event::Event;
@@ -430,13 +431,40 @@ impl CommitList {
430431
let remote_branches = self
431432
.remote_branches
432433
.get(&e.id)
433-
.map(|remote_branches| {
434-
remote_branches
434+
.and_then(|remote_branches| {
435+
let filtered_branches: Vec<_> = remote_branches
435436
.iter()
437+
.filter(|remote_branch| {
438+
self.local_branches
439+
.get(&e.id)
440+
.map_or(true, |local_branch| {
441+
local_branch.iter().any(
442+
|local_branch| {
443+
let has_corresponding_local_branch = match &local_branch.details {
444+
BranchDetails::Local(details) =>
445+
details
446+
.upstream
447+
.as_ref()
448+
.map_or(false, |upstream| upstream.reference == remote_branch.reference),
449+
BranchDetails::Remote(_) =>
450+
false,
451+
};
452+
453+
!has_corresponding_local_branch
454+
},
455+
)
456+
})
457+
})
436458
.map(|remote_branch| {
437459
format!("[{0}]", remote_branch.name)
438460
})
439-
.join(" ")
461+
.collect();
462+
463+
if filtered_branches.is_empty() {
464+
None
465+
} else {
466+
Some(filtered_branches.join(" "))
467+
}
440468
});
441469

442470
let marked = if any_marked {

0 commit comments

Comments
 (0)