merge_tools: simplify error message for complex conflicts

Since e48ace56d1e9, 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}" supported. Conflict summary for {0:?}:\n{1}"
)] )]
NotNormalFilesError(RepoPath, String), NotNormalFilesError(RepoPath, String),
#[error( #[error("The conflict at {path:?} has {sides} sides. At most 2 sides are supported.")]
"The conflict at {path:?} has {removes} removes and {adds} adds.\nAt most 1 remove and 2 \ ConflictTooComplicatedError { path: RepoPath, sides: usize },
adds are supported."
)]
ConflictTooComplicatedError {
path: RepoPath,
removes: usize,
adds: usize,
},
#[error( #[error(
"The output file is either unchanged or empty after the editor quit (run with --verbose \ "The output file is either unchanged or empty after the editor quit (run with --verbose \
to see the exact invocation)." 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 // We only support conflicts with 2 sides (3-way conflicts)
// not exist in the conflict base. Only 1 `adds` may exist for an if content.adds.len() > 2 {
// edit-delete conflict.
if content.removes.len() > 1 || content.adds.len() > 2 {
return Err(ConflictResolveError::ConflictTooComplicatedError { return Err(ConflictResolveError::ConflictTooComplicatedError {
path: repo_path.clone(), path: repo_path.clone(),
removes: content.removes.len(), sides: content.adds.len(),
adds: content.adds.len(),
}); });
}; };

View File

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