merge_tools: simplify error message for complex conflicts

Since e48ace56d1, the number of adds in the hunk is always exactly
one more than enumber of removes, so we can simplify the condition and
the error message accordingly.
This commit is contained in:
Martin von Zweigbergk 2023-06-06 14:13:28 -07:00 committed by Martin von Zweigbergk
parent 4a0fa4d9a0
commit ddb07e639c
2 changed files with 6 additions and 17 deletions

View file

@ -95,15 +95,8 @@ pub enum ConflictResolveError {
supported. Conflict summary for {0:?}:\n{1}"
)]
NotNormalFilesError(RepoPath, String),
#[error(
"The conflict at {path:?} has {removes} removes and {adds} adds.\nAt most 1 remove and 2 \
adds are supported."
)]
ConflictTooComplicatedError {
path: RepoPath,
removes: usize,
adds: usize,
},
#[error("The conflict at {path:?} has {sides} sides. At most 2 sides are supported.")]
ConflictTooComplicatedError { path: RepoPath, sides: usize },
#[error(
"The output file is either unchanged or empty after the editor quit (run with --verbose \
to see the exact invocation)."
@ -181,14 +174,11 @@ pub fn run_mergetool(
));
}
};
// The usual case is 1 `removes` and 2 `adds`. 0 `removes` means the file did
// not exist in the conflict base. Only 1 `adds` may exist for an
// edit-delete conflict.
if content.removes.len() > 1 || content.adds.len() > 2 {
// We only support conflicts with 2 sides (3-way conflicts)
if content.adds.len() > 2 {
return Err(ConflictResolveError::ConflictTooComplicatedError {
path: repo_path.clone(),
removes: content.removes.len(),
adds: content.adds.len(),
sides: content.adds.len(),
});
};

View file

@ -397,8 +397,7 @@ fn test_too_many_parents() {
let error = test_env.jj_cmd_failure(&repo_path, &["resolve"]);
insta::assert_snapshot!(error, @r###"
Error: Failed to use external tool to resolve: The conflict at "file" has 2 removes and 3 adds.
At most 1 remove and 2 adds are supported.
Error: Failed to use external tool to resolve: The conflict at "file" has 3 sides. At most 2 sides are supported.
"###);
}