print_conflicted_paths: simplify file conflicts before printing

This commit is contained in:
Benjamin Tan 2024-05-31 06:58:41 +08:00
parent 716ec37560
commit 9d4ac81c27
3 changed files with 5 additions and 6 deletions

View file

@ -1840,6 +1840,7 @@ pub fn print_conflicted_paths(
.map(|p| format!("{:width$}", p, width = max_path_len.min(32) + 3)); .map(|p| format!("{:width$}", p, width = max_path_len.min(32) + 3));
for ((_, conflict), formatted_path) in std::iter::zip(conflicts.iter(), formatted_paths) { for ((_, conflict), formatted_path) in std::iter::zip(conflicts.iter(), formatted_paths) {
let conflict = conflict.clone().simplify();
let sides = conflict.num_sides(); let sides = conflict.num_sides();
let n_adds = conflict.adds().flatten().count(); let n_adds = conflict.adds().flatten().count();
let deletions = sides - n_adds; let deletions = sides - n_adds;

View file

@ -523,11 +523,10 @@ fn test_simplify_conflict_sides() {
fileA: Ok(Conflicted([Some(File { id: FileId("d00491fd7e5bb6fa28c517a0bb32b8b506539d4d"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("0cfbf08886fca9a91cb753ec8734c84fcbe52c9f"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false })])) fileA: Ok(Conflicted([Some(File { id: FileId("d00491fd7e5bb6fa28c517a0bb32b8b506539d4d"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("0cfbf08886fca9a91cb753ec8734c84fcbe52c9f"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false })]))
fileB: Ok(Conflicted([Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("d00491fd7e5bb6fa28c517a0bb32b8b506539d4d"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("0cfbf08886fca9a91cb753ec8734c84fcbe52c9f"), executable: false })])) fileB: Ok(Conflicted([Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("d00491fd7e5bb6fa28c517a0bb32b8b506539d4d"), executable: false }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false }), Some(File { id: FileId("0cfbf08886fca9a91cb753ec8734c84fcbe52c9f"), executable: false })]))
"###); "###);
// TODO: The conflict should be simplified before being displayed.
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["resolve", "--list"]), insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["resolve", "--list"]),
@r###" @r###"
fileA 4-sided conflict fileA 2-sided conflict
fileB 4-sided conflict fileB 2-sided conflict
"###); "###);
insta::assert_snapshot!( insta::assert_snapshot!(
std::fs::read_to_string(repo_path.join("fileA")).unwrap(), @r###" std::fs::read_to_string(repo_path.join("fileA")).unwrap(), @r###"

View file

@ -207,13 +207,12 @@ fn test_status_simplify_conflict_sides() {
&[], &[],
); );
// TODO: The conflict should be simplified before being displayed.
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["status"]), insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["status"]),
@r###" @r###"
The working copy is clean The working copy is clean
There are unresolved conflicts at these paths: There are unresolved conflicts at these paths:
fileA 4-sided conflict fileA 2-sided conflict
fileB 4-sided conflict fileB 2-sided conflict
Working copy : nkmrtpmo 7b1cdcaa conflict | (conflict) (empty) conflict Working copy : nkmrtpmo 7b1cdcaa conflict | (conflict) (empty) conflict
Parent commit: kmkuslsw 18c1fb00 conflictA | (conflict) (empty) conflictA Parent commit: kmkuslsw 18c1fb00 conflictA | (conflict) (empty) conflictA
Parent commit: lylxulpl d11c92eb conflictB | (conflict) (empty) conflictB Parent commit: lylxulpl d11c92eb conflictB | (conflict) (empty) conflictB