@@ -6,6 +6,7 @@ use crate::{RefInfo, StacksFilter, branch, head_info, ref_info, state_handle, ui
6
6
use anyhow:: { Context , bail} ;
7
7
use bstr:: BString ;
8
8
use but_core:: RefMetadata ;
9
+ use but_core:: diff:: tree_changes;
9
10
use but_graph:: VirtualBranchesTomlMetadata ;
10
11
use gitbutler_command_context:: CommandContext ;
11
12
use gitbutler_commit:: commit_ext:: CommitExt ;
@@ -698,18 +699,37 @@ fn upstream_only_commits(
698
699
// If the id matches verbatim or if there is a known remote_id (in the case of LocalAndRemote) that matchies
699
700
c. id == commit. id ( ) . to_gix ( ) || matches ! ( & c. state, CommitState :: LocalAndRemote ( remote_id) if remote_id == & commit. id( ) . to_gix( ) )
700
701
} ) ;
702
+
701
703
// Ignore commits that strictly speaking are remote only, but they match a known local commit (rebase etc)
702
- if !matches_known_commit {
703
- let created_at = i128:: from ( commit. time ( ) . seconds ( ) ) * 1000 ;
704
- let upstream_commit = ui:: UpstreamCommit {
705
- id : commit. id ( ) . to_gix ( ) ,
706
- message : commit. message_bstr ( ) . into ( ) ,
707
- created_at,
708
- author : commit. author ( ) . into ( ) ,
709
- } ;
710
- upstream_only. push ( upstream_commit) ;
704
+ if matches_known_commit {
705
+ continue ;
706
+ }
707
+
708
+ let last_local_commit = local_and_remote. last ( ) ;
709
+
710
+ // If there's a last local commit, compare the trees
711
+ if let Some ( last_local_commit) = last_local_commit {
712
+ let lhs = last_local_commit. id ;
713
+ let rhs = commit. id ( ) . to_gix ( ) ;
714
+
715
+ // We don't care about upstream commits that bring no new changes.
716
+ // This helps us avoid showing 'upstream commits' after squashing commits or rebasing.
717
+ let ( changes, _) = tree_changes ( repo, Some ( lhs) , rhs) ?;
718
+ if changes. is_empty ( ) {
719
+ continue ;
720
+ }
711
721
}
722
+
723
+ let created_at = i128:: from ( commit. time ( ) . seconds ( ) ) * 1000 ;
724
+ let upstream_commit = ui:: UpstreamCommit {
725
+ id : commit. id ( ) . to_gix ( ) ,
726
+ message : commit. message_bstr ( ) . into ( ) ,
727
+ created_at,
728
+ author : commit. author ( ) . into ( ) ,
729
+ } ;
730
+ upstream_only. push ( upstream_commit) ;
712
731
}
732
+
713
733
upstream_only. reverse ( ) ;
714
734
715
735
Ok ( upstream_only)
0 commit comments