2561 lines · 88.0 KB · Rust
RawDownload
// Copyright 2022 The Jujutsu Authors//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at//// https://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License. use std::path::Path; use indoc::indoc;use testutils::TestResult; use crate::common::CommandOutput;use crate::common::TestEnvironment;use crate::common::TestWorkDir;use crate::common::create_commit_with_files;use crate::common::fake_editor_path; #[must_use]fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput {    work_dir.run_jj(["log", "-T", "bookmarks"])} #[test]fn test_resolution() -> TestResult {    let mut test_env = TestEnvironment::default();    let editor_script = test_env.set_up_fake_editor();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");     create_commit_with_files(&work_dir, "base", &[], &[("file", "base\n")]);    create_commit_with_files(&work_dir, "a", &["base"], &[("file", "a\n")]);    create_commit_with_files(&work_dir, "b", &["base"], &[("file", "b\n")]);    create_commit_with_files(&work_dir, "conflict", &["a", "b"], &[]);    // Test the setup    insta::assert_snapshot!(get_log_output(&work_dir), @"    @    conflict    ├─╮    │ ○  b    ○ │  a    ├─╯    ○  base    ◆    [EOF]    ");    insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @"    file    2-sided conflict    [EOF]    ");    insta::assert_snapshot!(work_dir.read_file("file"), @r#"    <<<<<<< conflict 1 of 1    %%%%%%% diff from: rlvkpnrz 1792382a "base"    \\\\\\\        to: zsuskuln 45537d53 "a"    -base    +a    +++++++ royxmykx 89d1b299 "b"    b    >>>>>>> conflict 1 of 1 ends    "#);    let setup_opid = work_dir.current_operation_id();     // Check that output file starts out empty and resolve the conflict    std::fs::write(        &editor_script,        ["dump editor0", "write\nresolution\n"].join("\0"),    )?;    let output = work_dir.run_jj(["resolve"]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Resolving conflicts in: file    Working copy  (@) now at: vruxwmqv 741263c9 conflict | conflict    Parent commit (@-)      : zsuskuln 45537d53 a | a    Parent commit (@-)      : royxmykx 89d1b299 b | b    Added 0 files, modified 1 files, removed 0 files    [EOF]    ");    insta::assert_snapshot!(        std::fs::read_to_string(test_env.env_root().join("editor0"))?, @"");    insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r#"    diff --git a/file b/file    index 0000000000..88425ec521 100644    --- a/file    +++ b/file    @@ -1,8 +1,1 @@ resolution    -<<<<<<< conflict 1 of 1    -%%%%%%% diff from: rlvkpnrz 1792382a "base"    -\\\\\\\        to: zsuskuln 45537d53 "a"    --base    -+a    -+++++++ royxmykx 89d1b299 "b"    -b    ->>>>>>> conflict 1 of 1 ends    +resolution    [EOF]    "#);    insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @"    ------- stderr -------    Error: No conflicts found at this revision    [EOF]    [exit status: 2]    ");     // Try again with --tool=<name>    work_dir.run_jj(["op", "restore", &setup_opid]).success();    std::fs::write(&editor_script, "write\nresolution\n")?;    let output = work_dir.run_jj([        "resolve",        "--config=ui.merge-editor='false'",        "--tool=fake-editor",    ]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Resolving conflicts in: file    Working copy  (@) now at: vruxwmqv 1f8a36f7 conflict | conflict    Parent commit (@-)      : zsuskuln 45537d53 a | a    Parent commit (@-)      : royxmykx 89d1b299 b | b    Added 0 files, modified 1 files, removed 0 files    [EOF]    ");    insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r#"    diff --git a/file b/file    index 0000000000..88425ec521 100644    --- a/file    +++ b/file    @@ -1,8 +1,1 @@ resolution    -<<<<<<< conflict 1 of 1    -%%%%%%% diff from: rlvkpnrz 1792382a "base"    -\\\\\\\        to: zsuskuln 45537d53 "a"    --base    -+a    -+++++++ royxmykx 89d1b299 "b"    -b    ->>>>>>> conflict 1 of 1 ends    +resolution    [EOF]    "#);    insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @"    ------- stderr -------    Error: No conflicts found at this revision    [EOF]    [exit status: 2]    ");     // Check that the output file starts with conflict markers if    // `merge-tool-edits-conflict-markers=true`    work_dir.run_jj(["op", "restore", &setup_opid]).success();    insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @"");    std::fs::write(        &editor_script,        ["dump editor1", "write\nresolution\n"].join("\0"),    )?;    work_dir        .run_jj([            "resolve",            "--config=merge-tools.fake-editor.merge-tool-edits-conflict-markers=true",        ])        .success();    insta::assert_snapshot!(        std::fs::read_to_string(test_env.env_root().join("editor1"))?, @r#"    <<<<<<< conflict 1 of 1    %%%%%%% diff from: rlvkpnrz 1792382a "base"    \\\\\\\        to: zsuskuln 45537d53 "a"    -base    +a    +++++++ royxmykx 89d1b299 "b"    b    >>>>>>> conflict 1 of 1 ends    "#);    insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r#"    diff --git a/file b/file    index 0000000000..88425ec521 100644    --- a/file    +++ b/file    @@ -1,8 +1,1 @@ resolution    -<<<<<<< conflict 1 of 1    -%%%%%%% diff from: rlvkpnrz 1792382a "base"    -\\\\\\\        to: zsuskuln 45537d53 "a"    --base    -+a    -+++++++ royxmykx 89d1b299 "b"    -b    ->>>>>>> conflict 1 of 1 ends    +resolution    [EOF]    "#);     // Check that if merge tool leaves conflict markers in output file and    // `merge-tool-edits-conflict-markers=true`, these markers are properly parsed.    work_dir.run_jj(["op", "restore", &setup_opid]).success();    insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @"");    std::fs::write(        &editor_script,        [            "dump editor2",            indoc! {"                write                <<<<<<<                %%%%%%%                -some                +fake                +++++++                conflict                >>>>>>>            "},        ]        .join("\0"),    )?;    let output = work_dir.run_jj([        "resolve",        "--config=merge-tools.fake-editor.merge-tool-edits-conflict-markers=true",    ]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Resolving conflicts in: file    Working copy  (@) now at: vruxwmqv a9cb79b1 conflict | (conflict) conflict    Parent commit (@-)      : zsuskuln 45537d53 a | a    Parent commit (@-)      : royxmykx 89d1b299 b | b    Added 0 files, modified 1 files, removed 0 files    Warning: There are unresolved conflicts at these paths:    file    2-sided conflict    New conflicts appeared in 1 commits:      vruxwmqv a9cb79b1 conflict | (conflict) conflict    Hint: To resolve the conflicts, start by creating a commit on top of    the conflicted commit:      jj new vruxwmqv    Then use `jj resolve`, or edit the conflict markers in the file directly.    Once the conflicts are resolved, you can inspect the result with `jj diff`.    Then run `jj squash` to move the resolution into the conflicted commit.    [EOF]    ");    insta::assert_snapshot!(        std::fs::read_to_string(test_env.env_root().join("editor2"))?, @r#"    <<<<<<< conflict 1 of 1    %%%%%%% diff from: rlvkpnrz 1792382a "base"    \\\\\\\        to: zsuskuln 45537d53 "a"    -base    +a    +++++++ royxmykx 89d1b299 "b"    b    >>>>>>> conflict 1 of 1 ends    "#);    // Note the "Modified" below    insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r#"    diff --git a/file b/file    --- a/file    +++ b/file    @@ -1,8 +1,8 @@ conflict     <<<<<<< conflict 1 of 1     %%%%%%% diff from: rlvkpnrz 1792382a "base"     \\\\\\\        to: zsuskuln 45537d53 "a"    --base    -+a    +-some    ++fake     +++++++ royxmykx 89d1b299 "b"    -b    +conflict     >>>>>>> conflict 1 of 1 ends    [EOF]    "#);    insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @"    file    2-sided conflict    [EOF]    ");     // Check that if merge tool leaves conflict markers in output file but    // `merge-tool-edits-conflict-markers=false` or is not specified,    // `jj` considers the conflict resolved.    work_dir.run_jj(["op", "restore", &setup_opid]).success();    insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @"");    std::fs::write(        &editor_script,        [            "dump editor3",            indoc! {"                write                <<<<<<<                %%%%%%%                -some                +fake                +++++++                conflict                >>>>>>>            "},        ]        .join("\0"),    )?;    let output = work_dir.run_jj(["resolve"]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Resolving conflicts in: file    Working copy  (@) now at: vruxwmqv 2cc7f5e3 conflict | conflict    Parent commit (@-)      : zsuskuln 45537d53 a | a    Parent commit (@-)      : royxmykx 89d1b299 b | b    Added 0 files, modified 1 files, removed 0 files    [EOF]    ");    insta::assert_snapshot!(        std::fs::read_to_string(test_env.env_root().join("editor3"))?, @"");    // Note the "Resolved" below    insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r#"    diff --git a/file b/file    index 0000000000..0610716cc1 100644    --- a/file    +++ b/file    @@ -1,8 +1,7 @@ conflict    -<<<<<<< conflict 1 of 1    -%%%%%%% diff from: rlvkpnrz 1792382a "base"    -\\\\\\\        to: zsuskuln 45537d53 "a"    --base    -+a    -+++++++ royxmykx 89d1b299 "b"    -b    ->>>>>>> conflict 1 of 1 ends    +<<<<<<<    +%%%%%%%    +-some    ++fake    ++++++++    +conflict    +>>>>>>>    [EOF]    "#);    insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @"    ------- stderr -------    Error: No conflicts found at this revision    [EOF]    [exit status: 2]    ");     // Check that merge tool can override conflict marker style setting, and that    // the merge tool can output Git-style conflict markers    work_dir.run_jj(["op", "restore", &setup_opid]).success();    insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @"");    std::fs::write(        &editor_script,        [            "dump editor4",            indoc! {"                write                <<<<<<<                some                |||||||                fake                =======                conflict                >>>>>>>            "},        ]        .join("\0"),    )?;    let output = work_dir.run_jj([        "resolve",        "--config=merge-tools.fake-editor.merge-tool-edits-conflict-markers=true",        "--config=merge-tools.fake-editor.conflict-marker-style=git",    ]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Resolving conflicts in: file    Working copy  (@) now at: vruxwmqv cd45e3c2 conflict | (conflict) conflict    Parent commit (@-)      : zsuskuln 45537d53 a | a    Parent commit (@-)      : royxmykx 89d1b299 b | b    Added 0 files, modified 1 files, removed 0 files    Warning: There are unresolved conflicts at these paths:    file    2-sided conflict    New conflicts appeared in 1 commits:      vruxwmqv cd45e3c2 conflict | (conflict) conflict    Hint: To resolve the conflicts, start by creating a commit on top of    the conflicted commit:      jj new vruxwmqv    Then use `jj resolve`, or edit the conflict markers in the file directly.    Once the conflicts are resolved, you can inspect the result with `jj diff`.    Then run `jj squash` to move the resolution into the conflicted commit.    [EOF]    ");    insta::assert_snapshot!(        std::fs::read_to_string(test_env.env_root().join("editor4"))?, @r#"    <<<<<<< zsuskuln 45537d53 "a"    a    ||||||| rlvkpnrz 1792382a "base"    base    =======    b    >>>>>>> royxmykx 89d1b299 "b"    "#);    insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r#"    diff --git a/file b/file    --- a/file    +++ b/file    @@ -1,8 +1,8 @@ conflict     <<<<<<< conflict 1 of 1     %%%%%%% diff from: rlvkpnrz 1792382a "base"     \\\\\\\        to: zsuskuln 45537d53 "a"    --base    -+a    +-fake    ++some     +++++++ royxmykx 89d1b299 "b"    -b    +conflict     >>>>>>> conflict 1 of 1 ends    [EOF]    "#);    insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @"    file    2-sided conflict    [EOF]    ");     // Check that merge tool can leave conflict markers by returning exit code 1    // when using `merge-conflict-exit-codes = [1]`. The Git "diff3" conflict    // markers should also be parsed correctly.    work_dir.run_jj(["op", "restore", &setup_opid]).success();    insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @"");    std::fs::write(        &editor_script,        [            "dump editor5",            indoc! {"                write                <<<<<<<                some                |||||||                fake                =======                conflict                >>>>>>>            "},            "fail",        ]        .join("\0"),    )?;    let output = work_dir.run_jj([        "resolve",        "--config=merge-tools.fake-editor.merge-conflict-exit-codes=[1]",    ]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Resolving conflicts in: file    Working copy  (@) now at: vruxwmqv 097d6249 conflict | (conflict) conflict    Parent commit (@-)      : zsuskuln 45537d53 a | a    Parent commit (@-)      : royxmykx 89d1b299 b | b    Added 0 files, modified 1 files, removed 0 files    Warning: There are unresolved conflicts at these paths:    file    2-sided conflict    New conflicts appeared in 1 commits:      vruxwmqv 097d6249 conflict | (conflict) conflict    Hint: To resolve the conflicts, start by creating a commit on top of    the conflicted commit:      jj new vruxwmqv    Then use `jj resolve`, or edit the conflict markers in the file directly.    Once the conflicts are resolved, you can inspect the result with `jj diff`.    Then run `jj squash` to move the resolution into the conflicted commit.    [EOF]    ");    insta::assert_snapshot!(        std::fs::read_to_string(test_env.env_root().join("editor5"))?, @"");    insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @r#"    diff --git a/file b/file    --- a/file    +++ b/file    @@ -1,8 +1,8 @@ conflict     <<<<<<< conflict 1 of 1     %%%%%%% diff from: rlvkpnrz 1792382a "base"     \\\\\\\        to: zsuskuln 45537d53 "a"    --base    -+a    +-fake    ++some     +++++++ royxmykx 89d1b299 "b"    -b    +conflict     >>>>>>> conflict 1 of 1 ends    [EOF]    "#);    insta::assert_snapshot!(work_dir.run_jj(["resolve", "--list"]), @"    file    2-sided conflict    [EOF]    ");     // Check that an error is reported if a merge tool indicated it would leave    // conflict markers, but the output file didn't contain valid conflict markers.    work_dir.run_jj(["op", "restore", &setup_opid]).success();    insta::assert_snapshot!(work_dir.run_jj(["diff", "--git"]), @"");    std::fs::write(        &editor_script,        [            indoc! {"                write                <<<<<<< this isn't diff3 style!                some                =======                conflict                >>>>>>>

Lines 1–500 of 2561.