// 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" @ 17a00fc21654 c ├─╮ │ ○ d370aee184ba b ○ │ 2443ea76b0b1 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 2443ea76b0b1 as kpqxywon f5b1e687 a [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 17a00fc21654 c ├─╮ │ ○ d370aee184ba b ○ │ 2443ea76b0b1 a ├─╯ │ ○ f5b1e68729d6 a ├─╯ ◆ 000000000000 [EOF] "); let output = work_dir.run_jj(["undo"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Undid operation: 6eead29c6998 (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 17a00fc21654 as lylxulpl ef3b0f3d c [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 17a00fc21654 c ├─╮ │ │ ○ ef3b0f3d1046 c ╭─┬─╯ │ ○ d370aee184ba b ○ │ 2443ea76b0b1 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" @ 921dde6e55c0 e ├─╮ │ ○ ebd06dba20ec d │ ○ c0cb3a0b73e7 c ○ │ 1394f625cbbd b ├─╯ ○ 2443ea76b0b1 a ◆ 000000000000 [EOF] "); let output = work_dir.run_jj(["duplicate", "b::"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 1394f625cbbd as wqnwkozp 3b74d969 b Duplicated 921dde6e55c0 as mouksmqu 8348ddce e [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 921dde6e55c0 e ├─╮ ○ │ 1394f625cbbd b │ │ ○ 8348ddcec733 e │ ╭─┤ │ ○ │ ebd06dba20ec d │ ○ │ c0cb3a0b73e7 c ├─╯ │ │ ○ 3b74d9691015 b ├───╯ ○ 2443ea76b0b1 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 1394f625cbbd as nkmrtpmo 0276d3d7 b [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 921dde6e55c0 e ├─╮ │ ○ ebd06dba20ec d │ ○ c0cb3a0b73e7 c ○ │ 1394f625cbbd b ├─╯ │ ○ 0276d3d7c24d b ├─╯ ○ 2443ea76b0b1 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 1394f625cbbd as xtnwkqum fa167d18 b Duplicated ebd06dba20ec as pqrnrkux 2181781b d Duplicated 921dde6e55c0 as ztxkyksq 0f7430f2 e [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 921dde6e55c0 e ├─╮ │ ○ ebd06dba20ec d ○ │ 1394f625cbbd b │ │ ○ 0f7430f2727a e │ │ ├─╮ │ │ │ ○ 2181781b4f81 d │ ├───╯ │ ○ │ c0cb3a0b73e7 c ├─╯ │ │ ○ fa167d18a83a b ├───╯ ○ 2443ea76b0b1 a ◆ 000000000000 [EOF] "); work_dir.run_jj(["undo"]).success(); // Reminder of the setup insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 921dde6e55c0 e ├─╮ │ ○ ebd06dba20ec d │ ○ c0cb3a0b73e7 c ○ │ 1394f625cbbd b ├─╯ ○ 2443ea76b0b1 a ◆ 000000000000 [EOF] "); let output = work_dir.run_jj(["duplicate", "d::", "a"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 2443ea76b0b1 as nlrtlrxv c6f7f8c4 a Duplicated ebd06dba20ec as plymsszl d94e4c55 d Duplicated 921dde6e55c0 as urrlptpw 9bd4389f e [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 921dde6e55c0 e ├─╮ │ ○ ebd06dba20ec d │ │ ○ 9bd4389f5d47 e ╭───┤ │ │ ○ d94e4c55a68b d │ ├─╯ │ ○ c0cb3a0b73e7 c ○ │ 1394f625cbbd b ├─╯ ○ 2443ea76b0b1 a │ ○ c6f7f8c4512e 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 2443ea76b0b1 as uuuvxpvw 0fe67a05 a Duplicated 1394f625cbbd as nmpuuozl e13ac0ad b Duplicated c0cb3a0b73e7 as kzpokyyw df53fa58 c Duplicated ebd06dba20ec as yxrlprzz 2f2442db d Duplicated 921dde6e55c0 as mvkzkxrl ee8fe64e e [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 921dde6e55c0 e ├─╮ │ ○ ebd06dba20ec d │ ○ c0cb3a0b73e7 c ○ │ 1394f625cbbd b ├─╯ ○ 2443ea76b0b1 a │ ○ ee8fe64ed254 e │ ├─╮ │ │ ○ 2f2442db08eb d │ │ ○ df53fa589286 c │ ○ │ e13ac0adabdf b │ ├─╯ │ ○ 0fe67a05989e 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" @ f7550bb42c6f d │ ○ b75b7aa4b90e c ├─╯ │ ○ 9a27d5939bef b ├─╯ │ ○ 17072aa2b823 a3 │ ○ 47df67757a64 a2 │ ○ 9e85a474f005 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 9e85a474f005 as nkmrtpmo 2944a632 a1 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ f7550bb42c6f d │ ○ 2944a6324f14 a1 │ ○ b75b7aa4b90e c ├─╯ │ ○ 9a27d5939bef b ├─╯ │ ○ 17072aa2b823 a3 │ ○ 47df67757a64 a2 │ ○ 9e85a474f005 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 9e85a474f005 as xtnwkqum 155f6a01 a1 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" ○ 155f6a012334 a1 ├─╮ │ @ f7550bb42c6f d ○ │ b75b7aa4b90e c ├─╯ │ ○ 9a27d5939bef b ├─╯ │ ○ 17072aa2b823 a3 │ ○ 47df67757a64 a2 │ ○ 9e85a474f005 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 9e85a474f005 as a descendant of itself Duplicated 9e85a474f005 as wvuyspvk 95585bb2 (empty) a1 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ f7550bb42c6f d │ ○ b75b7aa4b90e c ├─╯ │ ○ 9a27d5939bef b ├─╯ │ ○ 95585bb2fe05 a1 │ ○ 17072aa2b823 a3 │ ○ 47df67757a64 a2 │ ○ 9e85a474f005 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 9e85a474f005 as xlzxqlsl da0996fd a1 Duplicated 9a27d5939bef as vnkwvqxw 0af91ca8 b [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ f7550bb42c6f d │ ○ 0af91ca82d9c b │ │ ○ da0996fda8ce a1 │ ├─╯ │ ○ b75b7aa4b90e c ├─╯ │ ○ 9a27d5939bef b ├─╯ │ ○ 17072aa2b823 a3 │ ○ 47df67757a64 a2 │ ○ 9e85a474f005 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 9e85a474f005 as oupztwtk 2f519daa a1 Duplicated 9a27d5939bef as yxsqzptr c219a744 b [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" ○ c219a744e19c b ├─╮ │ │ ○ 2f519daab24d a1 ╭─┬─╯ │ @ f7550bb42c6f d ○ │ b75b7aa4b90e c ├─╯ │ ○ 9a27d5939bef b ├─╯ │ ○ 17072aa2b823 a3 │ ○ 47df67757a64 a2 │ ○ 9e85a474f005 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 9e85a474f005 as wtszoswq 806f2b56 a1 Duplicated 17072aa2b823 as qmykwtmu 161ce874 a3 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ f7550bb42c6f d │ ○ 161ce87408d5 a3 │ ○ 806f2b56207d a1 │ ○ b75b7aa4b90e c ├─╯ │ ○ 9a27d5939bef b ├─╯ │ ○ 17072aa2b823 a3 │ ○ 47df67757a64 a2 │ ○ 9e85a474f005 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 9e85a474f005 as rkoyqlrv 02cbff23 a1 Duplicated 17072aa2b823 as zxvrqtmq ddcfb95f a3 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" ○ ddcfb95ff7d8 a3 ○ 02cbff23a61d a1 ├─╮ │ @ f7550bb42c6f d ○ │ b75b7aa4b90e c ├─╯ │ ○ 9a27d5939bef b ├─╯ │ ○ 17072aa2b823 a3 │ ○ 47df67757a64 a2 │ ○ 9e85a474f005 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" @ 0cdd923e993a d2 ○ 0f21c5e185c5 d1 │ ○ 09560d60cac4 c2 │ ○ b27346e9a9bd c1 ├─╯ │ ○ 7b44470918f4 b2Lines 1–500 of 2442. 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" @ 17a00fc21654 c ├─╮ │ ○ d370aee184ba b ○ │ 2443ea76b0b1 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 2443ea76b0b1 as kpqxywon f5b1e687 a [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 17a00fc21654 c ├─╮ │ ○ d370aee184ba b ○ │ 2443ea76b0b1 a ├─╯ │ ○ f5b1e68729d6 a ├─╯ ◆ 000000000000 [EOF] "); let output = work_dir.run_jj(["undo"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Undid operation: 6eead29c6998 (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 17a00fc21654 as lylxulpl ef3b0f3d c [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 17a00fc21654 c ├─╮ │ │ ○ ef3b0f3d1046 c ╭─┬─╯ │ ○ d370aee184ba b ○ │ 2443ea76b0b1 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" @ 921dde6e55c0 e ├─╮ │ ○ ebd06dba20ec d │ ○ c0cb3a0b73e7 c ○ │ 1394f625cbbd b ├─╯ ○ 2443ea76b0b1 a ◆ 000000000000 [EOF] "); let output = work_dir.run_jj(["duplicate", "b::"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 1394f625cbbd as wqnwkozp 3b74d969 b Duplicated 921dde6e55c0 as mouksmqu 8348ddce e [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 921dde6e55c0 e ├─╮ ○ │ 1394f625cbbd b │ │ ○ 8348ddcec733 e │ ╭─┤ │ ○ │ ebd06dba20ec d │ ○ │ c0cb3a0b73e7 c ├─╯ │ │ ○ 3b74d9691015 b ├───╯ ○ 2443ea76b0b1 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 1394f625cbbd as nkmrtpmo 0276d3d7 b [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 921dde6e55c0 e ├─╮ │ ○ ebd06dba20ec d │ ○ c0cb3a0b73e7 c ○ │ 1394f625cbbd b ├─╯ │ ○ 0276d3d7c24d b ├─╯ ○ 2443ea76b0b1 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 1394f625cbbd as xtnwkqum fa167d18 b Duplicated ebd06dba20ec as pqrnrkux 2181781b d Duplicated 921dde6e55c0 as ztxkyksq 0f7430f2 e [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 921dde6e55c0 e ├─╮ │ ○ ebd06dba20ec d ○ │ 1394f625cbbd b │ │ ○ 0f7430f2727a e │ │ ├─╮ │ │ │ ○ 2181781b4f81 d │ ├───╯ │ ○ │ c0cb3a0b73e7 c ├─╯ │ │ ○ fa167d18a83a b ├───╯ ○ 2443ea76b0b1 a ◆ 000000000000 [EOF] "); work_dir.run_jj(["undo"]).success(); // Reminder of the setup insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 921dde6e55c0 e ├─╮ │ ○ ebd06dba20ec d │ ○ c0cb3a0b73e7 c ○ │ 1394f625cbbd b ├─╯ ○ 2443ea76b0b1 a ◆ 000000000000 [EOF] "); let output = work_dir.run_jj(["duplicate", "d::", "a"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Duplicated 2443ea76b0b1 as nlrtlrxv c6f7f8c4 a Duplicated ebd06dba20ec as plymsszl d94e4c55 d Duplicated 921dde6e55c0 as urrlptpw 9bd4389f e [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 921dde6e55c0 e ├─╮ │ ○ ebd06dba20ec d │ │ ○ 9bd4389f5d47 e ╭───┤ │ │ ○ d94e4c55a68b d │ ├─╯ │ ○ c0cb3a0b73e7 c ○ │ 1394f625cbbd b ├─╯ ○ 2443ea76b0b1 a │ ○ c6f7f8c4512e 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 2443ea76b0b1 as uuuvxpvw 0fe67a05 a Duplicated 1394f625cbbd as nmpuuozl e13ac0ad b Duplicated c0cb3a0b73e7 as kzpokyyw df53fa58 c Duplicated ebd06dba20ec as yxrlprzz 2f2442db d Duplicated 921dde6e55c0 as mvkzkxrl ee8fe64e e [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 921dde6e55c0 e ├─╮ │ ○ ebd06dba20ec d │ ○ c0cb3a0b73e7 c ○ │ 1394f625cbbd b ├─╯ ○ 2443ea76b0b1 a │ ○ ee8fe64ed254 e │ ├─╮ │ │ ○ 2f2442db08eb d │ │ ○ df53fa589286 c │ ○ │ e13ac0adabdf b │ ├─╯ │ ○ 0fe67a05989e 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" @ f7550bb42c6f d │ ○ b75b7aa4b90e c ├─╯ │ ○ 9a27d5939bef b ├─╯ │ ○ 17072aa2b823 a3 │ ○ 47df67757a64 a2 │ ○ 9e85a474f005 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 9e85a474f005 as nkmrtpmo 2944a632 a1 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ f7550bb42c6f d │ ○ 2944a6324f14 a1 │ ○ b75b7aa4b90e c ├─╯ │ ○ 9a27d5939bef b ├─╯ │ ○ 17072aa2b823 a3 │ ○ 47df67757a64 a2 │ ○ 9e85a474f005 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 9e85a474f005 as xtnwkqum 155f6a01 a1 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" ○ 155f6a012334 a1 ├─╮ │ @ f7550bb42c6f d ○ │ b75b7aa4b90e c ├─╯ │ ○ 9a27d5939bef b ├─╯ │ ○ 17072aa2b823 a3 │ ○ 47df67757a64 a2 │ ○ 9e85a474f005 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 9e85a474f005 as a descendant of itself Duplicated 9e85a474f005 as wvuyspvk 95585bb2 (empty) a1 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ f7550bb42c6f d │ ○ b75b7aa4b90e c ├─╯ │ ○ 9a27d5939bef b ├─╯ │ ○ 95585bb2fe05 a1 │ ○ 17072aa2b823 a3 │ ○ 47df67757a64 a2 │ ○ 9e85a474f005 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 9e85a474f005 as xlzxqlsl da0996fd a1 Duplicated 9a27d5939bef as vnkwvqxw 0af91ca8 b [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ f7550bb42c6f d │ ○ 0af91ca82d9c b │ │ ○ da0996fda8ce a1 │ ├─╯ │ ○ b75b7aa4b90e c ├─╯ │ ○ 9a27d5939bef b ├─╯ │ ○ 17072aa2b823 a3 │ ○ 47df67757a64 a2 │ ○ 9e85a474f005 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 9e85a474f005 as oupztwtk 2f519daa a1 Duplicated 9a27d5939bef as yxsqzptr c219a744 b [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" ○ c219a744e19c b ├─╮ │ │ ○ 2f519daab24d a1 ╭─┬─╯ │ @ f7550bb42c6f d ○ │ b75b7aa4b90e c ├─╯ │ ○ 9a27d5939bef b ├─╯ │ ○ 17072aa2b823 a3 │ ○ 47df67757a64 a2 │ ○ 9e85a474f005 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 9e85a474f005 as wtszoswq 806f2b56 a1 Duplicated 17072aa2b823 as qmykwtmu 161ce874 a3 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ f7550bb42c6f d │ ○ 161ce87408d5 a3 │ ○ 806f2b56207d a1 │ ○ b75b7aa4b90e c ├─╯ │ ○ 9a27d5939bef b ├─╯ │ ○ 17072aa2b823 a3 │ ○ 47df67757a64 a2 │ ○ 9e85a474f005 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 9e85a474f005 as rkoyqlrv 02cbff23 a1 Duplicated 17072aa2b823 as zxvrqtmq ddcfb95f a3 [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @r" ○ ddcfb95ff7d8 a3 ○ 02cbff23a61d a1 ├─╮ │ @ f7550bb42c6f d ○ │ b75b7aa4b90e c ├─╯ │ ○ 9a27d5939bef b ├─╯ │ ○ 17072aa2b823 a3 │ ○ 47df67757a64 a2 │ ○ 9e85a474f005 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" @ 0cdd923e993a d2 ○ 0f21c5e185c5 d1 │ ○ 09560d60cac4 c2 │ ○ b27346e9a9bd c1 ├─╯ │ ○ 7b44470918f4 b2