254 lines · 11.0 KB · Rust
RawDownload
// Copyright 2025 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 std::path::PathBuf; use testutils::TestResult; use crate::common::TestEnvironment; /// Integrating an already integrated operation is a no-op#[test]fn test_integrate_integrated_operation() {    let test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");     let output = work_dir.run_jj(["op", "integrate", "@"]);    insta::assert_snapshot!(output, @"");    let output = work_dir.run_jj(["op", "log"]);    insta::assert_snapshot!(output, @"    @  e39dc288903d test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00    │  add workspace 'default'    ○  000000000000 root()    [EOF]    ");} #[test]fn test_integrate_sibling_operation() -> TestResult {    let test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");     let base_op_id = work_dir.current_operation_id();    work_dir.run_jj(["new", "-m=first"]).success();    let unintegrated_id = work_dir.current_operation_id();    assert_ne!(unintegrated_id, base_op_id);    // Manually remove the last operation from the operation log    let heads_dir = work_dir        .root()        .join(PathBuf::from_iter([".jj", "repo", "op_heads", "heads"]));    std::fs::rename(        heads_dir.join(&unintegrated_id),        heads_dir.join(&base_op_id),    )?;    // We use --ignore-working-copy to prevent the automatic reloading of the repo    // at the unintegrated operation that's mentioned in    // `.jj/working_copy/checkout`.    let output = work_dir.run_jj(["new", "-m=second", "--ignore-working-copy"]);    insta::assert_snapshot!(output, @"");     // The working copy should now be at the old unintegrated sibling operation    let output = work_dir.run_jj(["op", "log"]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Internal error: The repo was loaded at operation e1478a7fd92e, which seems to be a sibling of the working copy's operation 7d77e263bae3    Hint: Run `jj op integrate 7d77e263bae3` to add the working copy's operation to the operation log.    [EOF]    [exit status: 255]    ");     // Integrate the operation    let output = work_dir.run_jj(["op", "integrate", &unintegrated_id]);    insta::assert_snapshot!(output, @"    ------- stderr -------    The specified operation has been integrated with other existing operations.    [EOF]    ");    let output = work_dir.run_jj(["op", "log"]);    insta::assert_snapshot!(output, @"    @    ba0f39fe4b1e test-username@host.example.com default@ 2001-02-03 04:05:11.000 +07:00 - 2001-02-03 04:05:11.000 +07:00    ├─╮  reconcile divergent operations    │ │  args: jj op integrate 7d77e263bae3bdfc8759dba931df2ae4015e3ee7e7af721569b9a9baaa68c7d6aee3ffaf368ce1787f27d38d4a6c643736bcc00b96233762b3988257eefc0316    ○ │  7d77e263bae3 test-username@host.example.com default@ 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00    │ │  new empty commit    │ │  args: jj new '-m=first'    │ ○  e1478a7fd92e test-username@host.example.com default@ 2001-02-03 04:05:09.000 +07:00 - 2001-02-03 04:05:09.000 +07:00    ├─╯  new empty commit    │    args: jj new '-m=second' --ignore-working-copy    ○  e39dc288903d test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00    │  add workspace 'default'    ○  000000000000 root()    [EOF]    ");    Ok(())} #[test]fn test_integrate_rebase_descendants() -> TestResult {    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(["new", "--no-edit", "-m=child 1"])        .success();     let base_op_id = work_dir.current_operation_id();    work_dir.run_jj(["new", "-m=child 2"]).success();    let unintegrated_id = work_dir.current_operation_id();    assert_ne!(unintegrated_id, base_op_id);    // Manually remove the last operation from the operation log    let heads_dir = work_dir        .root()        .join(PathBuf::from_iter([".jj", "repo", "op_heads", "heads"]));    std::fs::rename(        heads_dir.join(&unintegrated_id),        heads_dir.join(&base_op_id),    )?;     // We use --ignore-working-copy to prevent the automatic reloading of the repo    // at the unintegrated operation that's mentioned in    // `.jj/working_copy/checkout`.    let output = work_dir.run_jj(["describe", "-m=parent", "--ignore-working-copy"]);    insta::assert_snapshot!(output, @r"    ------- stderr -------    Rebased 1 descendant commits.    [EOF]    ");     // The working copy should now be at the old unintegrated sibling operation    let output = work_dir.run_jj(["op", "log"]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Internal error: The repo was loaded at operation 84902387a648, which seems to be a sibling of the working copy's operation 197cf9502bbc    Hint: Run `jj op integrate 197cf9502bbc` to add the working copy's operation to the operation log.    [EOF]    [exit status: 255]    ");     // Integrate the operation    let output = work_dir.run_jj(["op", "integrate", &unintegrated_id]);    insta::assert_snapshot!(output, @r"    ------- stderr -------    Rebased 1 descendant commits onto commits rewritten by other operation.    The specified operation has been integrated with other existing operations.    [EOF]    ");    let output = work_dir.run_jj(["op", "log"]);    insta::assert_snapshot!(output, @"    @    3d670a65589a test-username@host.example.com default@ 2001-02-03 04:05:12.000 +07:00 - 2001-02-03 04:05:12.000 +07:00    ├─╮  reconcile divergent operations    │ │  args: jj op integrate 197cf9502bbc92218bde53c51924379b87818fc2ad4bd5f9393296b35903f1f5097f7691673d007e29645b0a2239daedcca0cceb92cbabf0da0fdebefb5cbd30    ○ │  197cf9502bbc test-username@host.example.com default@ 2001-02-03 04:05:09.000 +07:00 - 2001-02-03 04:05:09.000 +07:00    │ │  new empty commit    │ │  args: jj new '-m=child 2'    │ ○  84902387a648 test-username@host.example.com default@ 2001-02-03 04:05:10.000 +07:00 - 2001-02-03 04:05:10.000 +07:00    ├─╯  describe commit e8849ae12c709f2321908879bc724fdb2ab8a781    │    args: jj describe '-m=parent' --ignore-working-copy    ○  bd3ed05fe6d3 test-username@host.example.com default@ 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00    │  new empty commit    │  args: jj new --no-edit '-m=child 1'    ○  e39dc288903d test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00    │  add workspace 'default'    ○  000000000000 root()    [EOF]    ");     // Child 2 was successfully rebased    let output = work_dir.run_jj(["log"]);    insta::assert_snapshot!(output, @"    @  kkmpptxz test.user@example.com 2001-02-03 08:05:12 9780be6d    │  (empty) child 2    │ ○  rlvkpnrz test.user@example.com 2001-02-03 08:05:10 ce1fb6c9    ├─╯  (empty) child 1    ○  qpvuntsm test.user@example.com 2001-02-03 08:05:10 5f8729eb    │  (empty) parent    ◆  zzzzzzzz root() 00000000    [EOF]    ");    Ok(())} #[test]fn test_integrate_concurrent_operations() -> TestResult {    let test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");     let base_op_id = work_dir.current_operation_id();    work_dir.run_jj(["describe", "-m=left"]).success();    let unintegrated_id = work_dir.current_operation_id();    assert_ne!(unintegrated_id, base_op_id);    // Manually remove the last operation from the operation log    let heads_dir = work_dir        .root()        .join(PathBuf::from_iter([".jj", "repo", "op_heads", "heads"]));    std::fs::rename(        heads_dir.join(&unintegrated_id),        heads_dir.join(&base_op_id),    )?;     // We use --ignore-working-copy to prevent the automatic reloading of the repo    // at the unintegrated operation that's mentioned in    // `.jj/working_copy/checkout`.    let output = work_dir.run_jj(["describe", "-m=right", "--ignore-working-copy"]);    insta::assert_snapshot!(output, @"");     // The working copy should now be at the old unintegrated sibling operation    let output = work_dir.run_jj(["op", "log"]);    insta::assert_snapshot!(output, @"    ------- stderr -------    Internal error: The repo was loaded at operation 864f75ed3a98, which seems to be a sibling of the working copy's operation 5f1385b5227b    Hint: Run `jj op integrate 5f1385b5227b` to add the working copy's operation to the operation log.    [EOF]    [exit status: 255]    ");     // Integrate the operation    let output = work_dir.run_jj(["op", "integrate", &unintegrated_id]);    insta::assert_snapshot!(output, @"    ------- stderr -------    The specified operation has been integrated with other existing operations.    [EOF]    ");    let output = work_dir.run_jj(["op", "log"]);    insta::assert_snapshot!(output, @"    @    7bae1689de7f test-username@host.example.com default@ 2001-02-03 04:05:11.000 +07:00 - 2001-02-03 04:05:11.000 +07:00    ├─╮  reconcile divergent operations    │ │  args: jj op integrate 5f1385b5227bbf44e5e80c6f010276f441ce133612d8fe14952f6e044bef807cf62337bbc0bbc4b1e5277d226337f115ecb5e350896a90f1d69bae1a7bd4a17c    ○ │  5f1385b5227b test-username@host.example.com default@ 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00    │ │  describe commit e8849ae12c709f2321908879bc724fdb2ab8a781    │ │  args: jj describe '-m=left'    │ ○  864f75ed3a98 test-username@host.example.com default@ 2001-02-03 04:05:09.000 +07:00 - 2001-02-03 04:05:09.000 +07:00    ├─╯  describe commit e8849ae12c709f2321908879bc724fdb2ab8a781    │    args: jj describe '-m=right' --ignore-working-copy    ○  e39dc288903d test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00    │  add workspace 'default'    ○  000000000000 root()    [EOF]    ");     // Produces divergence equivalent to concurrent `jj describe`    let output = work_dir.run_jj(["log"]);    insta::assert_snapshot!(output, @"    @  qpvuntsm/1 test.user@example.com 2001-02-03 08:05:08 3c52528f (divergent)    │  (empty) left    │ ○  qpvuntsm/0 test.user@example.com 2001-02-03 08:05:09 fc350e9c (divergent)    ├─╯  (empty) right    ◆  zzzzzzzz root() 00000000    [EOF]    ");    Ok(())}