// 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::CommandOutput;use crate::common::TestEnvironment;use crate::common::TestWorkDir;use crate::common::force_interactive; #[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 01f06d39 (empty) (no description set) Parent commit (@-) : kkmpptxz 7576de42 (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 a53dd783 (empty) (no description set) Parent commit (@-) : zsuskuln c5025ce1 (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 539f176b (empty) (no description set) Parent commit (@-) : rlvkpnrz 9439bf06 (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 a4d3accb (empty) (no description set) Parent commit (@-) : rlvkpnrz 9439bf06 (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 68a50538 (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 e5543950 (empty) 4 Parent commit (@-) : zsuskuln 83df6e43 (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 7a09c355 (empty) (no description set) Parent commit (@-) : mzvwutvl f02c921e (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 f02c921e (empty) 4 Parent commit (@-) : zsuskuln d2500577 (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 6fc6af46 (empty) third 2: rlvkpnrz 9439bf06 (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 6fc6af46 (empty) third 2: rlvkpnrz 9439bf06 (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 3522c887 (empty) fourth 2: zsuskuln 6fc6af46 (empty) third 3: rlvkpnrz 9439bf06 (empty) second q: quit the prompt enter the index of the commit you want to target: Working copy (@) now at: yostqsxw 683938a4 (empty) (no description set) Parent commit (@-) : zsuskuln 6fc6af46 (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 setup_opid = work_dir.current_operation_id(); let output = work_dir.run_jj(["prev"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Working copy (@) now at: vruxwmqv b64f323d (empty) (no description set) Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) [EOF] "); work_dir.run_jj(["op", "restore", &setup_opid]).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 22a08bc0 right | (empty) second 2: qpvuntsm 68a50538 left | (empty) first q: quit the prompt enter the index of the commit you want to target: Working copy (@) now at: qpvuntsm 68a50538 left | (empty) first Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set)Lines 1–500 of 1296. Load more
// 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::CommandOutput; use crate::common::TestEnvironment; use crate::common::TestWorkDir; use crate::common::force_interactive; #[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 01f06d39 (empty) (no description set) Parent commit (@-) : kkmpptxz 7576de42 (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 a53dd783 (empty) (no description set) Parent commit (@-) : zsuskuln c5025ce1 (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 539f176b (empty) (no description set) Parent commit (@-) : rlvkpnrz 9439bf06 (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 a4d3accb (empty) (no description set) Parent commit (@-) : rlvkpnrz 9439bf06 (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 68a50538 (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 e5543950 (empty) 4 Parent commit (@-) : zsuskuln 83df6e43 (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 7a09c355 (empty) (no description set) Parent commit (@-) : mzvwutvl f02c921e (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 f02c921e (empty) 4 Parent commit (@-) : zsuskuln d2500577 (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 6fc6af46 (empty) third 2: rlvkpnrz 9439bf06 (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 6fc6af46 (empty) third 2: rlvkpnrz 9439bf06 (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 3522c887 (empty) fourth 2: zsuskuln 6fc6af46 (empty) third 3: rlvkpnrz 9439bf06 (empty) second q: quit the prompt enter the index of the commit you want to target: Working copy (@) now at: yostqsxw 683938a4 (empty) (no description set) Parent commit (@-) : zsuskuln 6fc6af46 (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 setup_opid = work_dir.current_operation_id(); let output = work_dir.run_jj(["prev"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Working copy (@) now at: vruxwmqv b64f323d (empty) (no description set) Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) [EOF] "); work_dir.run_jj(["op", "restore", &setup_opid]).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 22a08bc0 right | (empty) second 2: qpvuntsm 68a50538 left | (empty) first q: quit the prompt enter the index of the commit you want to target: Working copy (@) now at: qpvuntsm 68a50538 left | (empty) first Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set)