Skip to content

bug: builtin merge tool select_right uses wrong tree for binary conflict resolution #8926

@scalecode-solutions

Description

@scalecode-solutions

Summary

In cli/src/merge_tools/builtin.rs, the select_right callback passed to apply_changes reads from the source tree instead of the destination tree. This is incorrect for binary conflict resolution.

Location

cli/src/merge_tools/builtin.rs, function apply_merge_builtin, line 742:

fn apply_merge_builtin(
    store: &Arc<Store>,
    tree: &MergedTree,
    changed_files: Vec<RepoPathBuf>,
    files: &[scm_record::File],
) -> BackendResult<MergedTree> {
    let mut tree_builder = MergedTreeBuilder::new(tree.clone());
    apply_changes(
        &mut tree_builder,
        changed_files,
        files,
        |path| tree.path_value(path),
        // FIXME: It doesn't make sense to select a new value from the source tree.
        // Presently, `select_right` is never actually called, since it is used to select binary
        // sections, but `make_merge_file` does not produce `Binary` sections for conflicted files.
        // This needs to be revisited when the UI becomes capable of representing binary conflicts.
        |path| tree.path_value(path),   // <-- both callbacks read from the same tree
        ...
    )
}

Both the select_left and select_right callbacks are identical — both read from tree (the source/base tree). select_right should read from a different tree (the destination/right side).

Current Impact

Currently not reachablemake_merge_file does not produce Binary sections for conflicted files, so select_right is never called. However, this will become an active bug when the UI gains the ability to represent and resolve binary conflicts.

Suggested Fix

select_right should read from the appropriate right-side tree, not the same tree as select_left. The correct tree needs to be threaded through from the merge context.


Found via static analysis with mvtk

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions