1294 lines · 40.4 KB · Rust
RawDownload
// Copyright 2023 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 crate::common::force_interactive;use crate::common::CommandOutput;use crate::common::TestEnvironment;use crate::common::TestWorkDir; #[test]fn test_next_simple() {    // Move from first => second.    // first    // |    // second    // |    // third    //    let test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");    // Create a simple linear history, which we'll traverse.    work_dir.run_jj(["commit", "-m", "first"]).success();    work_dir.run_jj(["commit", "-m", "second"]).success();    work_dir.run_jj(["commit", "-m", "third"]).success();    insta::assert_snapshot!(get_log_output(&work_dir), @r"    @  zsuskulnrvyr    ○  kkmpptxzrspx third    ○  rlvkpnrzqnoo second    ○  qpvuntsmwlqt first    ◆  zzzzzzzzzzzz    [EOF]    ");     // Move to `first`    work_dir.run_jj(["new", "@--"]).success();     insta::assert_snapshot!(get_log_output(&work_dir), @r"    @  royxmykxtrkr    │ ○  kkmpptxzrspx third    ├─╯    ○  rlvkpnrzqnoo second    ○  qpvuntsmwlqt first    ◆  zzzzzzzzzzzz    [EOF]    ");     let output = work_dir.run_jj(["next"]);    insta::assert_snapshot!(output, @r"    ------- stderr -------    Working copy  (@) now at: vruxwmqv 0c7d7732 (empty) (no description set)    Parent commit (@-)      : kkmpptxz 30056b0c (empty) third    [EOF]    ");     insta::assert_snapshot!(get_log_output(&work_dir), @r"    @  vruxwmqvtpmx    ○  kkmpptxzrspx third    ○  rlvkpnrzqnoo second    ○  qpvuntsmwlqt first    ◆  zzzzzzzzzzzz    [EOF]    ");} #[test]fn test_next_multiple() {    // Move from first => fourth.    let test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");    work_dir.run_jj(["commit", "-m", "first"]).success();    work_dir.run_jj(["commit", "-m", "second"]).success();    work_dir.run_jj(["commit", "-m", "third"]).success();    work_dir.run_jj(["commit", "-m", "fourth"]).success();    work_dir.run_jj(["new", "@---"]).success();     insta::assert_snapshot!(get_log_output(&work_dir), @r"    @  royxmykxtrkr    │ ○  zsuskulnrvyr fourth    │ ○  kkmpptxzrspx third    ├─╯    ○  rlvkpnrzqnoo second    ○  qpvuntsmwlqt first    ◆  zzzzzzzzzzzz    [EOF]    ");     // We should now be the child of the fourth commit.    let output = work_dir.run_jj(["next", "2"]);    insta::assert_snapshot!(output, @r"    ------- stderr -------    Working copy  (@) now at: vruxwmqv 41cc776d (empty) (no description set)    Parent commit (@-)      : zsuskuln 9d7e5e99 (empty) fourth    [EOF]    ");     insta::assert_snapshot!(get_log_output(&work_dir), @r"    @  vruxwmqvtpmx    ○  zsuskulnrvyr fourth    ○  kkmpptxzrspx third    ○  rlvkpnrzqnoo second    ○  qpvuntsmwlqt first    ◆  zzzzzzzzzzzz    [EOF]    ");} #[test]fn test_prev_simple() {    // Move @- from third to second.    let test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");    work_dir.run_jj(["commit", "-m", "first"]).success();    work_dir.run_jj(["commit", "-m", "second"]).success();    work_dir.run_jj(["commit", "-m", "third"]).success();    insta::assert_snapshot!(get_log_output(&work_dir), @r"    @  zsuskulnrvyr    ○  kkmpptxzrspx third    ○  rlvkpnrzqnoo second    ○  qpvuntsmwlqt first    ◆  zzzzzzzzzzzz    [EOF]    ");     let output = work_dir.run_jj(["prev"]);    insta::assert_snapshot!(output, @r"    ------- stderr -------    Working copy  (@) now at: royxmykx 6db74f64 (empty) (no description set)    Parent commit (@-)      : rlvkpnrz 9ed53a4a (empty) second    [EOF]    ");     insta::assert_snapshot!(get_log_output(&work_dir), @r"    @  royxmykxtrkr    │ ○  kkmpptxzrspx third    ├─╯    ○  rlvkpnrzqnoo second    ○  qpvuntsmwlqt first    ◆  zzzzzzzzzzzz    [EOF]    ");} #[test]fn test_prev_multiple_without_root() {    // Move @- from fourth to second.    let test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");    work_dir.run_jj(["commit", "-m", "first"]).success();    work_dir.run_jj(["commit", "-m", "second"]).success();    work_dir.run_jj(["commit", "-m", "third"]).success();    work_dir.run_jj(["commit", "-m", "fourth"]).success();    insta::assert_snapshot!(get_log_output(&work_dir), @r"    @  mzvwutvlkqwt    ○  zsuskulnrvyr fourth    ○  kkmpptxzrspx third    ○  rlvkpnrzqnoo second    ○  qpvuntsmwlqt first    ◆  zzzzzzzzzzzz    [EOF]    ");     let output = work_dir.run_jj(["prev", "2"]);    insta::assert_snapshot!(output, @r"    ------- stderr -------    Working copy  (@) now at: yqosqzyt 794ffd20 (empty) (no description set)    Parent commit (@-)      : rlvkpnrz 9ed53a4a (empty) second    [EOF]    ");     insta::assert_snapshot!(get_log_output(&work_dir), @r"    @  yqosqzytrlsw    │ ○  zsuskulnrvyr fourth    │ ○  kkmpptxzrspx third    ├─╯    ○  rlvkpnrzqnoo second    ○  qpvuntsmwlqt first    ◆  zzzzzzzzzzzz    [EOF]    ");} #[test]fn test_next_exceeding_history() {    // Try to step beyond the current repos history.    let test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");    work_dir.run_jj(["commit", "-m", "first"]).success();    work_dir.run_jj(["commit", "-m", "second"]).success();    work_dir.run_jj(["commit", "-m", "third"]).success();    work_dir.run_jj(["edit", "-r", "@--"]).success();     insta::assert_snapshot!(get_log_output(&work_dir), @r"    ○  kkmpptxzrspx third    @  rlvkpnrzqnoo second    ○  qpvuntsmwlqt first    ◆  zzzzzzzzzzzz    [EOF]    ");     // `jj next` beyond existing history fails.    let output = work_dir.run_jj(["next", "3"]);    insta::assert_snapshot!(output, @r"    ------- stderr -------    Error: No other descendant found 3 commit(s) forward from the working copy parent(s)    Hint: Working copy parent: qpvuntsm fa15625b (empty) first    [EOF]    [exit status: 1]    ");} // The working copy commit is a child of a "fork" with two children on each// bookmark.#[test]fn test_next_parent_has_multiple_descendants() {    let test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");    // Setup.    work_dir.run_jj(["desc", "-m", "1"]).success();    work_dir.run_jj(["new", "-m", "2"]).success();    work_dir.run_jj(["new", "root()", "-m", "3"]).success();    work_dir.run_jj(["new", "-m", "4"]).success();    work_dir.run_jj(["edit", "description(3)"]).success();    insta::assert_snapshot!(get_log_output(&work_dir), @r"    ○  mzvwutvlkqwt 4    @  zsuskulnrvyr 3    │ ○  kkmpptxzrspx 2    │ ○  qpvuntsmwlqt 1    ├─╯    ◆  zzzzzzzzzzzz    [EOF]    ");     let output = work_dir.run_jj(["next", "--edit"]);    insta::assert_snapshot!(output, @r"    ------- stderr -------    Working copy  (@) now at: mzvwutvl 1b8531ce (empty) 4    Parent commit (@-)      : zsuskuln b1394455 (empty) 3    [EOF]    ");    insta::assert_snapshot!(get_log_output(&work_dir), @r"    @  mzvwutvlkqwt 4    ○  zsuskulnrvyr 3    │ ○  kkmpptxzrspx 2    │ ○  qpvuntsmwlqt 1    ├─╯    ◆  zzzzzzzzzzzz    [EOF]    ");} #[test]fn test_next_with_merge_commit_parent() {    let test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");    // Setup.    work_dir.run_jj(["desc", "-m", "1"]).success();    work_dir.run_jj(["new", "root()", "-m", "2"]).success();    work_dir        .run_jj(["new", "description(1)", "description(2)", "-m", "3"])        .success();    work_dir.run_jj(["new", "-m", "4"]).success();    work_dir.run_jj(["prev", "0"]).success();    insta::assert_snapshot!(get_log_output(&work_dir), @r"    @  royxmykxtrkr    │ ○  mzvwutvlkqwt 4    ├─╯    ○    zsuskulnrvyr 3    ├─╮    │ ○  kkmpptxzrspx 2    ○ │  qpvuntsmwlqt 1    ├─╯    ◆  zzzzzzzzzzzz    [EOF]    ");     let output = work_dir.run_jj(["next"]);    insta::assert_snapshot!(output, @r"    ------- stderr -------    Working copy  (@) now at: vruxwmqv e2cefcb7 (empty) (no description set)    Parent commit (@-)      : mzvwutvl b54bbdea (empty) 4    [EOF]    ");    insta::assert_snapshot!(get_log_output(&work_dir), @r"    @  vruxwmqvtpmx    ○  mzvwutvlkqwt 4    ○    zsuskulnrvyr 3    ├─╮    │ ○  kkmpptxzrspx 2    ○ │  qpvuntsmwlqt 1    ├─╯    ◆  zzzzzzzzzzzz    [EOF]    ");} #[test]fn test_next_on_merge_commit() {    let test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");    // Setup.    work_dir.run_jj(["desc", "-m", "1"]).success();    work_dir.run_jj(["new", "root()", "-m", "2"]).success();    work_dir        .run_jj(["new", "description(1)", "description(2)", "-m", "3"])        .success();    work_dir.run_jj(["new", "-m", "4"]).success();    work_dir.run_jj(["edit", "description(3)"]).success();    insta::assert_snapshot!(get_log_output(&work_dir), @r"    ○  mzvwutvlkqwt 4    @    zsuskulnrvyr 3    ├─╮    │ ○  kkmpptxzrspx 2    ○ │  qpvuntsmwlqt 1    ├─╯    ◆  zzzzzzzzzzzz    [EOF]    ");     let output = work_dir.run_jj(["next", "--edit"]);    insta::assert_snapshot!(output, @r"    ------- stderr -------    Working copy  (@) now at: mzvwutvl b54bbdea (empty) 4    Parent commit (@-)      : zsuskuln 5542f0b4 (empty) 3    [EOF]    ");    insta::assert_snapshot!(get_log_output(&work_dir), @r"    @  mzvwutvlkqwt 4    ○    zsuskulnrvyr 3    ├─╮    │ ○  kkmpptxzrspx 2    ○ │  qpvuntsmwlqt 1    ├─╯    ◆  zzzzzzzzzzzz    [EOF]    ");} #[test]fn test_next_fails_on_bookmarking_children_no_stdin() {    let test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");    work_dir.run_jj(["commit", "-m", "first"]).success();    work_dir.run_jj(["commit", "-m", "second"]).success();    work_dir.run_jj(["new", "@--"]).success();    work_dir.run_jj(["commit", "-m", "third"]).success();    work_dir.run_jj(["new", "@--"]).success();     insta::assert_snapshot!(get_log_output(&work_dir), @r"    @  royxmykxtrkr    │ ○  zsuskulnrvyr third    ├─╯    │ ○  rlvkpnrzqnoo second    ├─╯    ○  qpvuntsmwlqt first    ◆  zzzzzzzzzzzz    [EOF]    ");     // Try to advance the working copy commit.    let output = work_dir.run_jj(["next"]);    insta::assert_snapshot!(output, @r"    ------- stderr -------    ambiguous next commit, choose one to target:    1: zsuskuln 5f24490d (empty) third    2: rlvkpnrz 9ed53a4a (empty) second    q: quit the prompt    Error: Cannot prompt for input since the output is not connected to a terminal    [EOF]    [exit status: 1]    ");} #[test]fn test_next_fails_on_bookmarking_children_quit_prompt() {    let test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");    work_dir.run_jj(["commit", "-m", "first"]).success();    work_dir.run_jj(["commit", "-m", "second"]).success();    work_dir.run_jj(["new", "@--"]).success();    work_dir.run_jj(["commit", "-m", "third"]).success();    work_dir.run_jj(["new", "@--"]).success();     insta::assert_snapshot!(get_log_output(&work_dir), @r"    @  royxmykxtrkr    │ ○  zsuskulnrvyr third    ├─╯    │ ○  rlvkpnrzqnoo second    ├─╯    ○  qpvuntsmwlqt first    ◆  zzzzzzzzzzzz    [EOF]    ");     // Try to advance the working copy commit.    let output = work_dir.run_jj_with(|cmd| force_interactive(cmd).arg("next").write_stdin("q\n"));    insta::assert_snapshot!(output, @r"    ------- stderr -------    ambiguous next commit, choose one to target:    1: zsuskuln 5f24490d (empty) third    2: rlvkpnrz 9ed53a4a (empty) second    q: quit the prompt    enter the index of the commit you want to target: Error: ambiguous target commit    [EOF]    [exit status: 1]    ");} #[test]fn test_next_choose_bookmarking_child() {    let test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");    work_dir.run_jj(["commit", "-m", "first"]).success();    work_dir.run_jj(["commit", "-m", "second"]).success();    work_dir.run_jj(["new", "@--"]).success();    work_dir.run_jj(["commit", "-m", "third"]).success();    work_dir.run_jj(["new", "@--"]).success();    work_dir.run_jj(["commit", "-m", "fourth"]).success();    work_dir.run_jj(["new", "@--"]).success();    // Advance the working copy commit.    let output = work_dir.run_jj_with(|cmd| force_interactive(cmd).arg("next").write_stdin("2\n"));    insta::assert_snapshot!(output, @r"    ------- stderr -------    ambiguous next commit, choose one to target:    1: royxmykx d00fe885 (empty) fourth    2: zsuskuln 5f24490d (empty) third    3: rlvkpnrz 9ed53a4a (empty) second    q: quit the prompt    enter the index of the commit you want to target: Working copy  (@) now at: yostqsxw 5c8fa96d (empty) (no description set)    Parent commit (@-)      : zsuskuln 5f24490d (empty) third    [EOF]    ");} #[test]fn test_prev_on_merge_commit() {    let test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");    work_dir.run_jj(["desc", "-m", "first"]).success();    work_dir.run_jj(["bookmark", "c", "-r@", "left"]).success();    work_dir.run_jj(["new", "root()", "-m", "second"]).success();    work_dir.run_jj(["bookmark", "c", "-r@", "right"]).success();    work_dir.run_jj(["new", "left", "right"]).success();     // Check that the graph looks the way we expect.    insta::assert_snapshot!(get_log_output(&work_dir), @r"    @    royxmykxtrkr    ├─╮    │ ○  zsuskulnrvyr right second    ○ │  qpvuntsmwlqt left first    ├─╯    ◆  zzzzzzzzzzzz    [EOF]    ");     let output = work_dir.run_jj(["prev"]);    insta::assert_snapshot!(output, @r"    ------- stderr -------    Working copy  (@) now at: vruxwmqv 41658cf4 (empty) (no description set)    Parent commit (@-)      : zzzzzzzz 00000000 (empty) (no description set)    [EOF]    ");     work_dir.run_jj(["undo"]).success();    let output = work_dir.run_jj_with(|cmd| {        force_interactive(cmd)            .args(["prev", "--edit"])            .write_stdin("2\n")    });    insta::assert_snapshot!(output, @r"    ------- stderr -------    ambiguous prev commit, choose one to target:    1: zsuskuln b0d21db3 right | (empty) second    2: qpvuntsm fa15625b left | (empty) first    q: quit the prompt    enter the index of the commit you want to target: Working copy  (@) now at: qpvuntsm fa15625b left | (empty) first    Parent commit (@-)      : zzzzzzzz 00000000 (empty) (no description set)    [EOF]

Lines 1–500 of 1294.