Skip to content

Commit

Permalink
view: also merge git_heads when merging views
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
martinvonz committed Jan 10, 2023
1 parent 5db0d84 commit 7b79367
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/tests/test_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transaction>) -> Arc<ReadonlyRepo> {
Expand Down

0 comments on commit 7b79367

Please sign in to comment.