Panic when one of the files to merge contains conflicts in diff2 format #520

Open
opened 2025-07-21 21:16:17 +02:00 by wetneb · 1 comment
Owner

If mergiraf solve is invoked on files where one of the revisions already contains conflicts represented in diff2 format (without the base part), then this leads to a panic:

thread 'main' panicked at src/line_based.rs:27:10:
diffy-imara returned a merge that we cannot parse the conflicts of: "Mergiraf cannot solve conflicts displayed in the diff2 style"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Even though such cases should only happen when the user has committed a file with conflicts into git (which is bad), we should make sure that:

  • we don't panic
  • any conflict that is already present in one of the base revisions (be it in diff2 / diff3 format) isn't treated as an actual conflict that mergiraf is meant to solve (as it's part of the source). This could be achieved by:
    • dynamically picking a conflict marker size which doesn't appear in the source revisions, or
    • plugging into diffy-imara at a lower level, so that we don't have to re-parse its output

A reproducing test case is attached (taken from https://github.com/qiskit/qiskit-terra)

If `mergiraf solve` is invoked on files where one of the revisions already contains conflicts represented in diff2 format (without the base part), then this leads to a panic: ``` thread 'main' panicked at src/line_based.rs:27:10: diffy-imara returned a merge that we cannot parse the conflicts of: "Mergiraf cannot solve conflicts displayed in the diff2 style" note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` Even though such cases should only happen when the user has committed a file with conflicts into git (which is bad), we should make sure that: * we don't panic * any conflict that is already present in one of the base revisions (be it in diff2 / diff3 format) isn't treated as an actual conflict that mergiraf is meant to solve (as it's part of the source). This could be achieved by: * dynamically picking a conflict marker size which doesn't appear in the source revisions, or * plugging into diffy-imara at a lower level, so that we don't have to re-parse its output A reproducing test case is attached (taken from https://github.com/qiskit/qiskit-terra)
3.1 KiB
Author
Owner

If the leftover conflict is part of a comment block, the source file can be parsed and this can also trigger another panic somewhere else:

thread 'main' panicked at src/parsed_merge.rs:334:25:
internal error: entered unreachable code: wouldn't have been a conflict in the first place

Attached is another minimized test case.

If the leftover conflict is part of a comment block, the source file can be parsed and this can also trigger another panic somewhere else: ``` thread 'main' panicked at src/parsed_merge.rs:334:25: internal error: entered unreachable code: wouldn't have been a conflict in the first place ``` Attached is another minimized test case.
wetneb self-assigned this 2025-10-11 12:56:30 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: mergiraf/mergiraf#520
No description provided.