From 7b7936793ca0279598f86884ac24e584174c21dc Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 17 Dec 2022 12:14:53 -0800 Subject: [PATCH] view: also merge `git_heads` when merging views I don't know if I had just forgotten to merge `git_heads` when I added it to the view object, but it seems like it should be merged just like refs. --- lib/src/repo.rs | 12 ++++++++++++ lib/tests/test_view.rs | 3 +-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 62b8def615..3db46c9f78 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -37,6 +37,7 @@ use crate::op_store::{ BranchTarget, OpStore, OperationId, OperationMetadata, RefTarget, WorkspaceId, }; use crate::operation::Operation; +use crate::refs::merge_ref_targets; use crate::rewrite::DescendantRebaser; use crate::settings::{RepoSettings, UserSettings}; use crate::simple_op_heads_store::SimpleOpHeadsStore; @@ -1022,6 +1023,17 @@ impl MutableRepo { other_target.as_ref(), ); } + + if let Some(new_git_head) = merge_ref_targets( + self.index.as_index_ref(), + self.view().git_head(), + base.git_head(), + other.git_head(), + ) { + self.set_git_head(new_git_head); + } else { + self.clear_git_head(); + } } /// Finds and records commits that were rewritten or abandoned between diff --git a/lib/tests/test_view.rs b/lib/tests/test_view.rs index 3445051cd4..9189b53628 100644 --- a/lib/tests/test_view.rs +++ b/lib/tests/test_view.rs @@ -462,8 +462,7 @@ fn test_merge_views_git_heads() { removes: vec![tx0_head.id().clone()], adds: vec![tx1_head.id().clone(), tx2_head.id().clone()], }; - // TODO: Should be equal - assert_ne!(repo.view().git_head(), Some(&expected_git_head)); + assert_eq!(repo.view().git_head(), Some(&expected_git_head)); } fn commit_transactions(settings: &UserSettings, txs: Vec) -> Arc {