possible mitigation for the case when a conflicting branch is incorrectly not unapplied base update

This commit is contained in:
Kiril Videlov 2024-07-21 22:04:46 +02:00
parent a148f90ccb
commit 581a793773
No known key found for this signature in database
GPG Key ID: A4C733025427C471

View File

@ -38,7 +38,7 @@ pub(crate) fn get_workspace_head(project_repo: &ProjectRepository) -> Result<git
.context("failed to get target")?; .context("failed to get target")?;
let repo: &git2::Repository = project_repo.repo(); let repo: &git2::Repository = project_repo.repo();
let virtual_branches: Vec<Branch> = vb_state.list_branches_in_workspace()?; let mut virtual_branches: Vec<Branch> = vb_state.list_branches_in_workspace()?;
let target_commit = repo.find_commit(target.sha)?; let target_commit = repo.find_commit(target.sha)?;
let mut workspace_tree = target_commit.tree()?; let mut workspace_tree = target_commit.tree()?;
@ -51,7 +51,7 @@ pub(crate) fn get_workspace_head(project_repo: &ProjectRepository) -> Result<git
let merge_base = repo.merge_base(first_branch.head, merge_parent)?; let merge_base = repo.merge_base(first_branch.head, merge_parent)?;
workspace_tree = repo.find_commit(merge_base)?.tree()?; workspace_tree = repo.find_commit(merge_base)?.tree()?;
} else { } else {
for branch in &virtual_branches { for branch in virtual_branches.iter_mut() {
let branch_tree = repo.find_commit(branch.head)?.tree()?; let branch_tree = repo.find_commit(branch.head)?.tree()?;
let merge_tree = repo.find_commit(target.sha)?.tree()?; let merge_tree = repo.find_commit(target.sha)?.tree()?;
let mut index = repo.merge_trees(&merge_tree, &workspace_tree, &branch_tree, None)?; let mut index = repo.merge_trees(&merge_tree, &workspace_tree, &branch_tree, None)?;
@ -59,7 +59,11 @@ pub(crate) fn get_workspace_head(project_repo: &ProjectRepository) -> Result<git
if !index.has_conflicts() { if !index.has_conflicts() {
workspace_tree = repo.find_tree(index.write_tree_to(repo)?)?; workspace_tree = repo.find_tree(index.write_tree_to(repo)?)?;
} else { } else {
return Err(anyhow!("Merge conflict between base and {:?}", branch.name)); // This branch should have already been unapplied during the "update" command but for some reason that failed
tracing::warn!("Merge conflict between base and {:?}", branch.name);
branch.applied = false;
branch.in_workspace = false;
vb_state.set_branch(branch.clone())?;
} }
} }
} }