2542 lines · 81.5 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::CommandOutput;use crate::common::TestEnvironment;use crate::common::TestWorkDir;use crate::common::create_commit; #[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), @"    @    387b928721d9   c    ├─╮    │ ○  d18ca3e87135   b    ○ │  7d980be7a1d4   a    ├─╯    ◆  000000000000    [EOF]    ");     let output = work_dir.run_jj(["duplicate", "all()"]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Error: Cannot duplicate the root commit    [EOF]    [exit status: 1]    ");     let output = work_dir.run_jj(["duplicate", "none()"]);    insta::assert_snapshot!(output, @"    ------- stderr -------    No revisions to duplicate.    [EOF]    ");     let output = work_dir.run_jj(["duplicate", "a"]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Duplicated 7d980be7a1d4 as kpqxywon 13eb8bd0 a    [EOF]    ");    insta::assert_snapshot!(get_log_output(&work_dir), @"    @    387b928721d9   c    ├─╮    │ ○  d18ca3e87135   b    ○ │  7d980be7a1d4   a    ├─╯    │ ○  13eb8bd0a547   a    ├─╯    ◆  000000000000    [EOF]    ");     let output = work_dir.run_jj(["undo"]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Undid operation: 76386e059136 (2001-02-03 08:05:17) duplicate 1 commit(s)    Restored to operation: 9fdb56d75a27 (2001-02-03 08:05:13) create bookmark c pointing to commit 387b928721d9f2efff819ccce81868f32537d71f    [EOF]    ");    let output = work_dir.run_jj(["duplicate" /* duplicates `c` */]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Duplicated 387b928721d9 as lylxulpl 71c64df5 c    [EOF]    ");    insta::assert_snapshot!(get_log_output(&work_dir), @"    @    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), @"    @    0559be9bd4d0   e    ├─╮    │ ○  a2dbb1aad514   d    │ ○  991a7501d660   c    ○ │  123b4d91f6e5   b    ├─╯    ○  7d980be7a1d4   a    ◆  000000000000    [EOF]    ");    let setup_opid = work_dir.current_operation_id();     let output = work_dir.run_jj(["duplicate", "b::"]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Duplicated 123b4d91f6e5 as wqnwkozp 10059c86 b    Duplicated 0559be9bd4d0 as mouksmqu 0afe2f34 e    [EOF]    ");    insta::assert_snapshot!(get_log_output(&work_dir), @"    @    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(["op", "restore", &setup_opid]).success();    let output = work_dir.run_jj(["duplicate", "b", "b"]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Duplicated 123b4d91f6e5 as nkmrtpmo 1ccf2589 b    [EOF]    ");    insta::assert_snapshot!(get_log_output(&work_dir), @"    @    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(["op", "restore", &setup_opid]).success();    let output = work_dir.run_jj(["duplicate", "b::", "d::"]);    insta::assert_snapshot!(output, @"    ------- 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), @"    @    0559be9bd4d0   e    ├─╮    │ ○  a2dbb1aad514   d    ○ │  123b4d91f6e5   b    │ │ ○    b113bd5c550a   e    │ │ ├─╮    │ │ │ ○  6a17a96d77d2   d    │ ├───╯    │ ○ │  991a7501d660   c    ├─╯ │    │   ○  1a94ffc6e6aa   b    ├───╯    ○  7d980be7a1d4   a    ◆  000000000000    [EOF]    ");     work_dir.run_jj(["op", "restore", &setup_opid]).success();    // Reminder of the setup    insta::assert_snapshot!(get_log_output(&work_dir), @"    @    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, @"    ------- 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), @"    @    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(["op", "restore", &setup_opid]).success();    let output = work_dir.run_jj(["duplicate", "a::"]);    insta::assert_snapshot!(output, @"    ------- 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), @"    @    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), @"    @  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", "-o", "c"]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Duplicated 5d93a4b8f4bd as kxryzmor 08f0f980 a1    [EOF]    ");    insta::assert_snapshot!(get_log_output(&work_dir), @"    @  5248650c3314   d    │ ○  08f0f980b8ad   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", "-o", "c", "-o", "d"]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Duplicated 5d93a4b8f4bd as xznxytkn 0bad88fb a1    [EOF]    ");    insta::assert_snapshot!(get_log_output(&work_dir), @"    ○    0bad88fbab2e   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", "-o", "a3"]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Warning: Duplicating commit 5d93a4b8f4bd as a descendant of itself    Duplicated 5d93a4b8f4bd as tlkvzzqu 8351ae70 (empty) a1    [EOF]    ");    insta::assert_snapshot!(get_log_output(&work_dir), @"    @  5248650c3314   d    │ ○  22370aa928dc   c    ├─╯    │ ○  c406dbab05ac   b    ├─╯    │ ○  8351ae7027e4   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", "-o", "c"]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Duplicated 5d93a4b8f4bd as pzsxstzt 663f101c a1    Duplicated c406dbab05ac as nxkxtmvy b8a86167 b    [EOF]    ");    insta::assert_snapshot!(get_log_output(&work_dir), @"    @  5248650c3314   d    │ ○  b8a8616787a4   b    │ │ ○  663f101c476a   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", "-o", "c", "-o", "d"]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Duplicated 5d93a4b8f4bd as qmkrwlvp b0f531b0 a1    Duplicated c406dbab05ac as pkqrwoqq 0df6b6b2 b    [EOF]    ");    insta::assert_snapshot!(get_log_output(&work_dir), @"    ○    0df6b6b21bfe   b    ├─╮    │ │ ○  b0f531b01b33   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", "-o", "c"]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Duplicated 5d93a4b8f4bd as qwyusntz 5f1c245f a1    Duplicated 5fb83d2b58d6 as pwpvvyov 2a209b65 a3    [EOF]    ");    insta::assert_snapshot!(get_log_output(&work_dir), @"    @  5248650c3314   d    │ ○  2a209b658cd6   a3    │ ○  5f1c245fb9ae   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", "-o", "c", "-o", "d"]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Duplicated 5d93a4b8f4bd as soqnvnyz bc6678fd a1    Duplicated 5fb83d2b58d6 as nmmmqslz a35b7e76 a3    [EOF]    ");    insta::assert_snapshot!(get_log_output(&work_dir), @"    ○  a35b7e76b4dd   a3    ○    bc6678fdf2a5   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), @"    @  3e122d6a4b70   d2    ○  ae61a031221a   d1    │ ○  47a79ab4bbc6   c2    │ ○  9b24b49f717e   c1

Lines 1–500 of 2542.