// 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::create_commit;use crate::common::CommandOutput;use crate::common::TestEnvironment;use crate::common::TestWorkDir; #[test]fn test_duplicate() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); create_commit(&work_dir, "a", &[]); create_commit(&work_dir, "b", &[]); create_commit(&work_dir, "c", &["a", "b"]); // Test the setup insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 387b928721d9 c ├─╮ │ ○ d18ca3e87135 b ○ │ 7d980be7a1d4 a ├─╯ ◆ 000000000000 [EOF] "); let output = work_dir.run_jj(["duplicate", "all()"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: Cannot duplicate the root commit [EOF] [exit status: 1] "); let output = work_dir.run_jj(["duplicate", "none()"]); insta::assert_snapshot!(output, @r" ------- stderr ------- No revisions to duplicate. [EOF] "); let output = work_dir.run_jj(["duplicate", "a"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 7d980be7a1d4 as kpqxywon 13eb8bd0 a [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 387b928721d9 c ├─╮ │ ○ d18ca3e87135 b ○ │ 7d980be7a1d4 a ├─╯ │ ○ 13eb8bd0a547 a ├─╯ ◆ 000000000000 [EOF] "); let output = work_dir.run_jj(["undo"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Undid operation: 76386e059136 (2001-02-03 08:05:17) duplicate 1 commit(s) [EOF] "); let output = work_dir.run_jj(["duplicate" /* duplicates `c` */]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 387b928721d9 as lylxulpl 71c64df5 c [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 387b928721d9 c ├─╮ │ │ ○ 71c64df584dc c ╭─┬─╯ │ ○ d18ca3e87135 b ○ │ 7d980be7a1d4 a ├─╯ ◆ 000000000000 [EOF] ");} #[test]fn test_duplicate_many() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); create_commit(&work_dir, "a", &[]); create_commit(&work_dir, "b", &["a"]); create_commit(&work_dir, "c", &["a"]); create_commit(&work_dir, "d", &["c"]); create_commit(&work_dir, "e", &["b", "d"]); // Test the setup insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 0559be9bd4d0 e ├─╮ │ ○ a2dbb1aad514 d │ ○ 991a7501d660 c ○ │ 123b4d91f6e5 b ├─╯ ○ 7d980be7a1d4 a ◆ 000000000000 [EOF] "); let output = work_dir.run_jj(["duplicate", "b::"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 123b4d91f6e5 as wqnwkozp 10059c86 b Duplicated 0559be9bd4d0 as mouksmqu 0afe2f34 e [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 0559be9bd4d0 e ├─╮ ○ │ 123b4d91f6e5 b │ │ ○ 0afe2f348a93 e │ ╭─┤ │ ○ │ a2dbb1aad514 d │ ○ │ 991a7501d660 c ├─╯ │ │ ○ 10059c8651d7 b ├───╯ ○ 7d980be7a1d4 a ◆ 000000000000 [EOF] "); // Try specifying the same commit twice directly work_dir.run_jj(["undo"]).success(); let output = work_dir.run_jj(["duplicate", "b", "b"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 123b4d91f6e5 as nkmrtpmo 1ccf2589 b [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 0559be9bd4d0 e ├─╮ │ ○ a2dbb1aad514 d │ ○ 991a7501d660 c ○ │ 123b4d91f6e5 b ├─╯ │ ○ 1ccf2589bfd1 b ├─╯ ○ 7d980be7a1d4 a ◆ 000000000000 [EOF] "); // Try specifying the same commit twice indirectly work_dir.run_jj(["undo"]).success(); let output = work_dir.run_jj(["duplicate", "b::", "d::"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 123b4d91f6e5 as xtnwkqum 1a94ffc6 b Duplicated a2dbb1aad514 as pqrnrkux 6a17a96d d Duplicated 0559be9bd4d0 as ztxkyksq b113bd5c e [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 0559be9bd4d0 e ├─╮ │ ○ a2dbb1aad514 d ○ │ 123b4d91f6e5 b │ │ ○ b113bd5c550a e │ │ ├─╮ │ │ │ ○ 6a17a96d77d2 d │ ├───╯ │ ○ │ 991a7501d660 c ├─╯ │ │ ○ 1a94ffc6e6aa b ├───╯ ○ 7d980be7a1d4 a ◆ 000000000000 [EOF] "); work_dir.run_jj(["undo"]).success(); // Reminder of the setup insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 0559be9bd4d0 e ├─╮ │ ○ a2dbb1aad514 d │ ○ 991a7501d660 c ○ │ 123b4d91f6e5 b ├─╯ ○ 7d980be7a1d4 a ◆ 000000000000 [EOF] "); let output = work_dir.run_jj(["duplicate", "d::", "a"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 7d980be7a1d4 as nlrtlrxv 117dd806 a Duplicated a2dbb1aad514 as plymsszl f2ec1b7f d Duplicated 0559be9bd4d0 as urrlptpw 9e54f34c e [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 0559be9bd4d0 e ├─╮ │ ○ a2dbb1aad514 d │ │ ○ 9e54f34ca238 e ╭───┤ │ │ ○ f2ec1b7f4e82 d │ ├─╯ │ ○ 991a7501d660 c ○ │ 123b4d91f6e5 b ├─╯ ○ 7d980be7a1d4 a │ ○ 117dd80623e6 a ├─╯ ◆ 000000000000 [EOF] "); // Check for BUG -- makes too many 'a'-s, etc. work_dir.run_jj(["undo"]).success(); let output = work_dir.run_jj(["duplicate", "a::"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 7d980be7a1d4 as uuuvxpvw cb730319 a Duplicated 123b4d91f6e5 as nmpuuozl b00a23f6 b Duplicated 991a7501d660 as kzpokyyw 7c1b86d5 c Duplicated a2dbb1aad514 as yxrlprzz 2f5494bb d Duplicated 0559be9bd4d0 as mvkzkxrl 8a4c81fe e [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 0559be9bd4d0 e ├─╮ │ ○ a2dbb1aad514 d │ ○ 991a7501d660 c ○ │ 123b4d91f6e5 b ├─╯ ○ 7d980be7a1d4 a │ ○ 8a4c81fee5f1 e │ ├─╮ │ │ ○ 2f5494bb9bce d │ │ ○ 7c1b86d551da c │ ○ │ b00a23f660bf b │ ├─╯ │ ○ cb7303191ed7 a ├─╯ ◆ 000000000000 [EOF] ");} #[test]fn test_duplicate_destination() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); create_commit(&work_dir, "a1", &[]); create_commit(&work_dir, "a2", &["a1"]); create_commit(&work_dir, "a3", &["a2"]); create_commit(&work_dir, "b", &[]); create_commit(&work_dir, "c", &[]); create_commit(&work_dir, "d", &[]); let setup_opid = work_dir.current_operation_id(); // Test the setup insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 5248650c3314 d │ ○ 22370aa928dc c ├─╯ │ ○ c406dbab05ac b ├─╯ │ ○ 5fb83d2b58d6 a3 │ ○ 7bfd9fbe959c a2 │ ○ 5d93a4b8f4bd a1 ├─╯ ◆ 000000000000 [EOF] "); // Duplicate a single commit onto a single destination. let output = work_dir.run_jj(["duplicate", "a1", "-d", "c"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 5d93a4b8f4bd as nkmrtpmo f7a7a3f6 a1 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 5248650c3314 d │ ○ f7a7a3f627a2 a1 │ ○ 22370aa928dc c ├─╯ │ ○ c406dbab05ac b ├─╯ │ ○ 5fb83d2b58d6 a3 │ ○ 7bfd9fbe959c a2 │ ○ 5d93a4b8f4bd a1 ├─╯ ◆ 000000000000 [EOF] "); work_dir.run_jj(["op", "restore", &setup_opid]).success(); // Duplicate a single commit onto multiple destinations. let output = work_dir.run_jj(["duplicate", "a1", "-d", "c", "-d", "d"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 5d93a4b8f4bd as xtnwkqum a515a8a7 a1 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" ○ a515a8a7055d a1 ├─╮ │ @ 5248650c3314 d ○ │ 22370aa928dc c ├─╯ │ ○ c406dbab05ac b ├─╯ │ ○ 5fb83d2b58d6 a3 │ ○ 7bfd9fbe959c a2 │ ○ 5d93a4b8f4bd a1 ├─╯ ◆ 000000000000 [EOF] "); work_dir.run_jj(["op", "restore", &setup_opid]).success(); // Duplicate a single commit onto its descendant. let output = work_dir.run_jj(["duplicate", "a1", "-d", "a3"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Warning: Duplicating commit 5d93a4b8f4bd as a descendant of itself Duplicated 5d93a4b8f4bd as wvuyspvk d80473de (empty) a1 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 5248650c3314 d │ ○ 22370aa928dc c ├─╯ │ ○ c406dbab05ac b ├─╯ │ ○ d80473de843a a1 │ ○ 5fb83d2b58d6 a3 │ ○ 7bfd9fbe959c a2 │ ○ 5d93a4b8f4bd a1 ├─╯ ◆ 000000000000 [EOF] "); work_dir.run_jj(["op", "restore", &setup_opid]).success(); // Duplicate multiple commits without a direct ancestry relationship onto a // single destination. let output = work_dir.run_jj(["duplicate", "-r=a1", "-r=b", "-d", "c"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 5d93a4b8f4bd as xlzxqlsl bfc29032 a1 Duplicated c406dbab05ac as vnkwvqxw c57bb4be b [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 5248650c3314 d │ ○ c57bb4beac33 b │ │ ○ bfc29032c3ff a1 │ ├─╯ │ ○ 22370aa928dc c ├─╯ │ ○ c406dbab05ac b ├─╯ │ ○ 5fb83d2b58d6 a3 │ ○ 7bfd9fbe959c a2 │ ○ 5d93a4b8f4bd a1 ├─╯ ◆ 000000000000 [EOF] "); work_dir.run_jj(["op", "restore", &setup_opid]).success(); // Duplicate multiple commits without a direct ancestry relationship onto // multiple destinations. let output = work_dir.run_jj(["duplicate", "-r=a1", "b", "-d", "c", "-d", "d"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 5d93a4b8f4bd as oupztwtk 83113cdf a1 Duplicated c406dbab05ac as yxsqzptr 469ed79e b [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" ○ 469ed79e4b00 b ├─╮ │ │ ○ 83113cdff475 a1 ╭─┬─╯ │ @ 5248650c3314 d ○ │ 22370aa928dc c ├─╯ │ ○ c406dbab05ac b ├─╯ │ ○ 5fb83d2b58d6 a3 │ ○ 7bfd9fbe959c a2 │ ○ 5d93a4b8f4bd a1 ├─╯ ◆ 000000000000 [EOF] "); work_dir.run_jj(["op", "restore", &setup_opid]).success(); // Duplicate multiple commits with an ancestry relationship onto a // single destination. let output = work_dir.run_jj(["duplicate", "a1", "a3", "-d", "c"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 5d93a4b8f4bd as wtszoswq 31bc8e32 a1 Duplicated 5fb83d2b58d6 as qmykwtmu 2a318b78 a3 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 5248650c3314 d │ ○ 2a318b7805df a3 │ ○ 31bc8e32bcd5 a1 │ ○ 22370aa928dc c ├─╯ │ ○ c406dbab05ac b ├─╯ │ ○ 5fb83d2b58d6 a3 │ ○ 7bfd9fbe959c a2 │ ○ 5d93a4b8f4bd a1 ├─╯ ◆ 000000000000 [EOF] "); work_dir.run_jj(["op", "restore", &setup_opid]).success(); // Duplicate multiple commits with an ancestry relationship onto // multiple destinations. let output = work_dir.run_jj(["duplicate", "a1", "a3", "-d", "c", "-d", "d"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 5d93a4b8f4bd as rkoyqlrv d7d45f05 a1 Duplicated 5fb83d2b58d6 as zxvrqtmq 44d5cb38 a3 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" ○ 44d5cb3876a2 a3 ○ d7d45f051a3c a1 ├─╮ │ @ 5248650c3314 d ○ │ 22370aa928dc c ├─╯ │ ○ c406dbab05ac b ├─╯ │ ○ 5fb83d2b58d6 a3 │ ○ 7bfd9fbe959c a2 │ ○ 5d93a4b8f4bd a1 ├─╯ ◆ 000000000000 [EOF] ");} #[test]fn test_duplicate_insert_after() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); create_commit(&work_dir, "a1", &[]); create_commit(&work_dir, "a2", &["a1"]); create_commit(&work_dir, "a3", &["a2"]); create_commit(&work_dir, "a4", &["a3"]); create_commit(&work_dir, "b1", &[]); create_commit(&work_dir, "b2", &["b1"]); create_commit(&work_dir, "c1", &[]); create_commit(&work_dir, "c2", &["c1"]); create_commit(&work_dir, "d1", &[]); create_commit(&work_dir, "d2", &["d1"]); let setup_opid = work_dir.current_operation_id(); // Test the setup insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 3e122d6a4b70 d2 ○ ae61a031221a d1 │ ○ 47a79ab4bbc6 c2 │ ○ 9b24b49f717e c1 ├─╯ │ ○ 65b6f1fe6b41 b2Lines 1–500 of 2535. 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::create_commit; use crate::common::CommandOutput; use crate::common::TestEnvironment; use crate::common::TestWorkDir; #[test] fn test_duplicate() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); create_commit(&work_dir, "a", &[]); create_commit(&work_dir, "b", &[]); create_commit(&work_dir, "c", &["a", "b"]); // Test the setup insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 387b928721d9 c ├─╮ │ ○ d18ca3e87135 b ○ │ 7d980be7a1d4 a ├─╯ ◆ 000000000000 [EOF] "); let output = work_dir.run_jj(["duplicate", "all()"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: Cannot duplicate the root commit [EOF] [exit status: 1] "); let output = work_dir.run_jj(["duplicate", "none()"]); insta::assert_snapshot!(output, @r" ------- stderr ------- No revisions to duplicate. [EOF] "); let output = work_dir.run_jj(["duplicate", "a"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 7d980be7a1d4 as kpqxywon 13eb8bd0 a [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 387b928721d9 c ├─╮ │ ○ d18ca3e87135 b ○ │ 7d980be7a1d4 a ├─╯ │ ○ 13eb8bd0a547 a ├─╯ ◆ 000000000000 [EOF] "); let output = work_dir.run_jj(["undo"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Undid operation: 76386e059136 (2001-02-03 08:05:17) duplicate 1 commit(s) [EOF] "); let output = work_dir.run_jj(["duplicate" /* duplicates `c` */]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 387b928721d9 as lylxulpl 71c64df5 c [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 387b928721d9 c ├─╮ │ │ ○ 71c64df584dc c ╭─┬─╯ │ ○ d18ca3e87135 b ○ │ 7d980be7a1d4 a ├─╯ ◆ 000000000000 [EOF] "); } #[test] fn test_duplicate_many() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); create_commit(&work_dir, "a", &[]); create_commit(&work_dir, "b", &["a"]); create_commit(&work_dir, "c", &["a"]); create_commit(&work_dir, "d", &["c"]); create_commit(&work_dir, "e", &["b", "d"]); // Test the setup insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 0559be9bd4d0 e ├─╮ │ ○ a2dbb1aad514 d │ ○ 991a7501d660 c ○ │ 123b4d91f6e5 b ├─╯ ○ 7d980be7a1d4 a ◆ 000000000000 [EOF] "); let output = work_dir.run_jj(["duplicate", "b::"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 123b4d91f6e5 as wqnwkozp 10059c86 b Duplicated 0559be9bd4d0 as mouksmqu 0afe2f34 e [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 0559be9bd4d0 e ├─╮ ○ │ 123b4d91f6e5 b │ │ ○ 0afe2f348a93 e │ ╭─┤ │ ○ │ a2dbb1aad514 d │ ○ │ 991a7501d660 c ├─╯ │ │ ○ 10059c8651d7 b ├───╯ ○ 7d980be7a1d4 a ◆ 000000000000 [EOF] "); // Try specifying the same commit twice directly work_dir.run_jj(["undo"]).success(); let output = work_dir.run_jj(["duplicate", "b", "b"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 123b4d91f6e5 as nkmrtpmo 1ccf2589 b [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 0559be9bd4d0 e ├─╮ │ ○ a2dbb1aad514 d │ ○ 991a7501d660 c ○ │ 123b4d91f6e5 b ├─╯ │ ○ 1ccf2589bfd1 b ├─╯ ○ 7d980be7a1d4 a ◆ 000000000000 [EOF] "); // Try specifying the same commit twice indirectly work_dir.run_jj(["undo"]).success(); let output = work_dir.run_jj(["duplicate", "b::", "d::"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 123b4d91f6e5 as xtnwkqum 1a94ffc6 b Duplicated a2dbb1aad514 as pqrnrkux 6a17a96d d Duplicated 0559be9bd4d0 as ztxkyksq b113bd5c e [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 0559be9bd4d0 e ├─╮ │ ○ a2dbb1aad514 d ○ │ 123b4d91f6e5 b │ │ ○ b113bd5c550a e │ │ ├─╮ │ │ │ ○ 6a17a96d77d2 d │ ├───╯ │ ○ │ 991a7501d660 c ├─╯ │ │ ○ 1a94ffc6e6aa b ├───╯ ○ 7d980be7a1d4 a ◆ 000000000000 [EOF] "); work_dir.run_jj(["undo"]).success(); // Reminder of the setup insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 0559be9bd4d0 e ├─╮ │ ○ a2dbb1aad514 d │ ○ 991a7501d660 c ○ │ 123b4d91f6e5 b ├─╯ ○ 7d980be7a1d4 a ◆ 000000000000 [EOF] "); let output = work_dir.run_jj(["duplicate", "d::", "a"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 7d980be7a1d4 as nlrtlrxv 117dd806 a Duplicated a2dbb1aad514 as plymsszl f2ec1b7f d Duplicated 0559be9bd4d0 as urrlptpw 9e54f34c e [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 0559be9bd4d0 e ├─╮ │ ○ a2dbb1aad514 d │ │ ○ 9e54f34ca238 e ╭───┤ │ │ ○ f2ec1b7f4e82 d │ ├─╯ │ ○ 991a7501d660 c ○ │ 123b4d91f6e5 b ├─╯ ○ 7d980be7a1d4 a │ ○ 117dd80623e6 a ├─╯ ◆ 000000000000 [EOF] "); // Check for BUG -- makes too many 'a'-s, etc. work_dir.run_jj(["undo"]).success(); let output = work_dir.run_jj(["duplicate", "a::"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 7d980be7a1d4 as uuuvxpvw cb730319 a Duplicated 123b4d91f6e5 as nmpuuozl b00a23f6 b Duplicated 991a7501d660 as kzpokyyw 7c1b86d5 c Duplicated a2dbb1aad514 as yxrlprzz 2f5494bb d Duplicated 0559be9bd4d0 as mvkzkxrl 8a4c81fe e [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 0559be9bd4d0 e ├─╮ │ ○ a2dbb1aad514 d │ ○ 991a7501d660 c ○ │ 123b4d91f6e5 b ├─╯ ○ 7d980be7a1d4 a │ ○ 8a4c81fee5f1 e │ ├─╮ │ │ ○ 2f5494bb9bce d │ │ ○ 7c1b86d551da c │ ○ │ b00a23f660bf b │ ├─╯ │ ○ cb7303191ed7 a ├─╯ ◆ 000000000000 [EOF] "); } #[test] fn test_duplicate_destination() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); create_commit(&work_dir, "a1", &[]); create_commit(&work_dir, "a2", &["a1"]); create_commit(&work_dir, "a3", &["a2"]); create_commit(&work_dir, "b", &[]); create_commit(&work_dir, "c", &[]); create_commit(&work_dir, "d", &[]); let setup_opid = work_dir.current_operation_id(); // Test the setup insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 5248650c3314 d │ ○ 22370aa928dc c ├─╯ │ ○ c406dbab05ac b ├─╯ │ ○ 5fb83d2b58d6 a3 │ ○ 7bfd9fbe959c a2 │ ○ 5d93a4b8f4bd a1 ├─╯ ◆ 000000000000 [EOF] "); // Duplicate a single commit onto a single destination. let output = work_dir.run_jj(["duplicate", "a1", "-d", "c"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 5d93a4b8f4bd as nkmrtpmo f7a7a3f6 a1 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 5248650c3314 d │ ○ f7a7a3f627a2 a1 │ ○ 22370aa928dc c ├─╯ │ ○ c406dbab05ac b ├─╯ │ ○ 5fb83d2b58d6 a3 │ ○ 7bfd9fbe959c a2 │ ○ 5d93a4b8f4bd a1 ├─╯ ◆ 000000000000 [EOF] "); work_dir.run_jj(["op", "restore", &setup_opid]).success(); // Duplicate a single commit onto multiple destinations. let output = work_dir.run_jj(["duplicate", "a1", "-d", "c", "-d", "d"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 5d93a4b8f4bd as xtnwkqum a515a8a7 a1 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" ○ a515a8a7055d a1 ├─╮ │ @ 5248650c3314 d ○ │ 22370aa928dc c ├─╯ │ ○ c406dbab05ac b ├─╯ │ ○ 5fb83d2b58d6 a3 │ ○ 7bfd9fbe959c a2 │ ○ 5d93a4b8f4bd a1 ├─╯ ◆ 000000000000 [EOF] "); work_dir.run_jj(["op", "restore", &setup_opid]).success(); // Duplicate a single commit onto its descendant. let output = work_dir.run_jj(["duplicate", "a1", "-d", "a3"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Warning: Duplicating commit 5d93a4b8f4bd as a descendant of itself Duplicated 5d93a4b8f4bd as wvuyspvk d80473de (empty) a1 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 5248650c3314 d │ ○ 22370aa928dc c ├─╯ │ ○ c406dbab05ac b ├─╯ │ ○ d80473de843a a1 │ ○ 5fb83d2b58d6 a3 │ ○ 7bfd9fbe959c a2 │ ○ 5d93a4b8f4bd a1 ├─╯ ◆ 000000000000 [EOF] "); work_dir.run_jj(["op", "restore", &setup_opid]).success(); // Duplicate multiple commits without a direct ancestry relationship onto a // single destination. let output = work_dir.run_jj(["duplicate", "-r=a1", "-r=b", "-d", "c"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 5d93a4b8f4bd as xlzxqlsl bfc29032 a1 Duplicated c406dbab05ac as vnkwvqxw c57bb4be b [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 5248650c3314 d │ ○ c57bb4beac33 b │ │ ○ bfc29032c3ff a1 │ ├─╯ │ ○ 22370aa928dc c ├─╯ │ ○ c406dbab05ac b ├─╯ │ ○ 5fb83d2b58d6 a3 │ ○ 7bfd9fbe959c a2 │ ○ 5d93a4b8f4bd a1 ├─╯ ◆ 000000000000 [EOF] "); work_dir.run_jj(["op", "restore", &setup_opid]).success(); // Duplicate multiple commits without a direct ancestry relationship onto // multiple destinations. let output = work_dir.run_jj(["duplicate", "-r=a1", "b", "-d", "c", "-d", "d"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 5d93a4b8f4bd as oupztwtk 83113cdf a1 Duplicated c406dbab05ac as yxsqzptr 469ed79e b [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" ○ 469ed79e4b00 b ├─╮ │ │ ○ 83113cdff475 a1 ╭─┬─╯ │ @ 5248650c3314 d ○ │ 22370aa928dc c ├─╯ │ ○ c406dbab05ac b ├─╯ │ ○ 5fb83d2b58d6 a3 │ ○ 7bfd9fbe959c a2 │ ○ 5d93a4b8f4bd a1 ├─╯ ◆ 000000000000 [EOF] "); work_dir.run_jj(["op", "restore", &setup_opid]).success(); // Duplicate multiple commits with an ancestry relationship onto a // single destination. let output = work_dir.run_jj(["duplicate", "a1", "a3", "-d", "c"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 5d93a4b8f4bd as wtszoswq 31bc8e32 a1 Duplicated 5fb83d2b58d6 as qmykwtmu 2a318b78 a3 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 5248650c3314 d │ ○ 2a318b7805df a3 │ ○ 31bc8e32bcd5 a1 │ ○ 22370aa928dc c ├─╯ │ ○ c406dbab05ac b ├─╯ │ ○ 5fb83d2b58d6 a3 │ ○ 7bfd9fbe959c a2 │ ○ 5d93a4b8f4bd a1 ├─╯ ◆ 000000000000 [EOF] "); work_dir.run_jj(["op", "restore", &setup_opid]).success(); // Duplicate multiple commits with an ancestry relationship onto // multiple destinations. let output = work_dir.run_jj(["duplicate", "a1", "a3", "-d", "c", "-d", "d"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 5d93a4b8f4bd as rkoyqlrv d7d45f05 a1 Duplicated 5fb83d2b58d6 as zxvrqtmq 44d5cb38 a3 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" ○ 44d5cb3876a2 a3 ○ d7d45f051a3c a1 ├─╮ │ @ 5248650c3314 d ○ │ 22370aa928dc c ├─╯ │ ○ c406dbab05ac b ├─╯ │ ○ 5fb83d2b58d6 a3 │ ○ 7bfd9fbe959c a2 │ ○ 5d93a4b8f4bd a1 ├─╯ ◆ 000000000000 [EOF] "); } #[test] fn test_duplicate_insert_after() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); create_commit(&work_dir, "a1", &[]); create_commit(&work_dir, "a2", &["a1"]); create_commit(&work_dir, "a3", &["a2"]); create_commit(&work_dir, "a4", &["a3"]); create_commit(&work_dir, "b1", &[]); create_commit(&work_dir, "b2", &["b1"]); create_commit(&work_dir, "c1", &[]); create_commit(&work_dir, "c2", &["c1"]); create_commit(&work_dir, "d1", &[]); create_commit(&work_dir, "d2", &["d1"]); let setup_opid = work_dir.current_operation_id(); // Test the setup insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 3e122d6a4b70 d2 ○ ae61a031221a d1 │ ○ 47a79ab4bbc6 c2 │ ○ 9b24b49f717e c1 ├─╯ │ ○ 65b6f1fe6b41 b2