2537 lines · 93.8 KB · Rust
RawDownload
// Copyright 2022 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::Path;use std::path::PathBuf; use itertools::Itertools as _;use regex::Regex;use testutils::git; use crate::common::to_toml_value;use crate::common::CommandOutput;use crate::common::TestEnvironment;use crate::common::TestWorkDir; #[test]fn test_op_log() {    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(["describe", "-m", "description 0"])        .success();     let output = work_dir.run_jj(["op", "log"]);    insta::assert_snapshot!(output, @r"    @  d009cfc04993 test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00    │  describe commit 230dd059e1b059aefc0da06a2e5a7dbf22362f22    │  args: jj describe -m 'description 0'    ○  eac759b9ab75 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]    ");    let op_log_lines = output.stdout.raw().lines().collect_vec();    let add_workspace_id = op_log_lines[3].split(' ').nth(2).unwrap();     // Can load the repo at a specific operation ID    insta::assert_snapshot!(get_log_output(&work_dir, add_workspace_id), @r"    @  230dd059e1b059aefc0da06a2e5a7dbf22362f22    ◆  0000000000000000000000000000000000000000    [EOF]    ");    // "@" resolves to the head operation    insta::assert_snapshot!(get_log_output(&work_dir, "@"), @r"    @  19611c995a342c01f525583e5fcafdd211f6d009    ◆  0000000000000000000000000000000000000000    [EOF]    ");    // "@-" resolves to the parent of the head operation    insta::assert_snapshot!(get_log_output(&work_dir, "@-"), @r"    @  230dd059e1b059aefc0da06a2e5a7dbf22362f22    ◆  0000000000000000000000000000000000000000    [EOF]    ");    insta::assert_snapshot!(work_dir.run_jj(["log", "--at-op", "@---"]), @r#"    ------- stderr -------    Error: The "@---" expression resolved to no operations    [EOF]    [exit status: 1]    "#);     // We get a reasonable message if an invalid operation ID is specified    insta::assert_snapshot!(work_dir.run_jj(["log", "--at-op", "foo"]), @r#"    ------- stderr -------    Error: Operation ID "foo" is not a valid hexadecimal prefix    [EOF]    [exit status: 1]    "#);     let output = work_dir.run_jj(["op", "log", "--op-diff"]);    insta::assert_snapshot!(output, @r"    @  d009cfc04993 test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00    │  describe commit 230dd059e1b059aefc0da06a2e5a7dbf22362f22    │  args: jj describe -m 'description 0'    │    │  Changed commits:    │  ○  + qpvuntsm 19611c99 (empty) description 0    │     - qpvuntsm hidden 230dd059 (empty) (no description set)    │    │  Changed working copy default@:    │  + qpvuntsm 19611c99 (empty) description 0    │  - qpvuntsm hidden 230dd059 (empty) (no description set)    ○  eac759b9ab75 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'    │    │  Changed commits:    │  ○  + qpvuntsm 230dd059 (empty) (no description set)    │    │  Changed working copy default@:    │  + qpvuntsm 230dd059 (empty) (no description set)    │  - (absent)    ○  000000000000 root()    [EOF]    ");     work_dir        .run_jj(["describe", "-m", "description 1"])        .success();    work_dir        .run_jj([            "describe",            "-m",            "description 2",            "--at-op",            add_workspace_id,        ])        .success();    insta::assert_snapshot!(work_dir.run_jj(["log", "--at-op", "@-"]), @r#"    ------- stderr -------    Error: The "@" expression resolved to more than one operation    Hint: Try specifying one of the operations by ID: fd29e648380b, 3e8ef7115a0c    [EOF]    [exit status: 1]    "#);} #[test]fn test_op_log_with_custom_symbols() {    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(["describe", "-m", "description 0"])        .success();     let output = work_dir.run_jj([        "op",        "log",        "--config=templates.op_log_node='if(current_operation, \"$\", if(root, \"┴\", \"┝\"))'",    ]);    insta::assert_snapshot!(output, @r"    $  d009cfc04993 test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00    │  describe commit 230dd059e1b059aefc0da06a2e5a7dbf22362f22    │  args: jj describe -m 'description 0'    ┝  eac759b9ab75 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_op_log_with_no_template() {    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", "log", "-T"]);    insta::assert_snapshot!(output, @r"    ------- stderr -------    error: a value is required for '--template <TEMPLATE>' but none was supplied     For more information, try '--help'.    Hint: The following template aliases are defined:    - builtin_config_list    - builtin_config_list_detailed    - builtin_draft_commit_description    - builtin_log_comfortable    - builtin_log_compact    - builtin_log_compact_full_description    - builtin_log_detailed    - builtin_log_node    - builtin_log_node_ascii    - builtin_log_oneline    - builtin_op_log_comfortable    - builtin_op_log_compact    - builtin_op_log_node    - builtin_op_log_node_ascii    - builtin_op_log_oneline    - commit_summary_separator    - description_placeholder    - email_placeholder    - name_placeholder    [EOF]    [exit status: 2]    ");} #[test]fn test_op_log_limit() {    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", "log", "-Tdescription", "--limit=1"]);    insta::assert_snapshot!(output, @r"    @  add workspace 'default'    [EOF]    ");} #[test]fn test_op_log_no_graph() {    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", "log", "--no-graph", "--color=always"]);    insta::assert_snapshot!(output, @r"    eac759b9ab75 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]    ");     let output = work_dir.run_jj(["op", "log", "--op-diff", "--no-graph"]);    insta::assert_snapshot!(output, @r"    eac759b9ab75 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'     Changed commits:    + qpvuntsm 230dd059 (empty) (no description set)     Changed working copy default@:    + qpvuntsm 230dd059 (empty) (no description set)    - (absent)    000000000000 root()    [EOF]    ");} #[test]fn test_op_log_reversed() {    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(["describe", "-m", "description 0"])        .success();     let output = work_dir.run_jj(["op", "log", "--reversed"]);    insta::assert_snapshot!(output, @r"    ○  000000000000 root()    ○  eac759b9ab75 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'    @  d009cfc04993 test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00       describe commit 230dd059e1b059aefc0da06a2e5a7dbf22362f22       args: jj describe -m 'description 0'    [EOF]    ");     work_dir        .run_jj(["describe", "-m", "description 1", "--at-op", "@-"])        .success();     // Should be able to display log with fork and branch points    let output = work_dir.run_jj(["op", "log", "--reversed"]);    insta::assert_snapshot!(output, @r"    ○  000000000000 root()    ○    eac759b9ab75 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'    │ ○  8e3e726be123 test-username@host.example.com 2001-02-03 04:05:10.000 +07:00 - 2001-02-03 04:05:10.000 +07:00    │ │  describe commit 230dd059e1b059aefc0da06a2e5a7dbf22362f22    │ │  args: jj describe -m 'description 1' --at-op @-    ○ │  d009cfc04993 test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00    ├─╯  describe commit 230dd059e1b059aefc0da06a2e5a7dbf22362f22    │    args: jj describe -m 'description 0'    @  e4538ffdc13d test-username@host.example.com 2001-02-03 04:05:11.000 +07:00 - 2001-02-03 04:05:11.000 +07:00       reconcile divergent operations       args: jj op log --reversed    [EOF]    ------- stderr -------    Concurrent modification detected, resolving automatically.    [EOF]    ");     // Should work correctly with `--no-graph`    let output = work_dir.run_jj(["op", "log", "--reversed", "--no-graph"]);    insta::assert_snapshot!(output, @r"    000000000000 root()    eac759b9ab75 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'    8e3e726be123 test-username@host.example.com 2001-02-03 04:05:10.000 +07:00 - 2001-02-03 04:05:10.000 +07:00    describe commit 230dd059e1b059aefc0da06a2e5a7dbf22362f22    args: jj describe -m 'description 1' --at-op @-    d009cfc04993 test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00    describe commit 230dd059e1b059aefc0da06a2e5a7dbf22362f22    args: jj describe -m 'description 0'    e4538ffdc13d test-username@host.example.com 2001-02-03 04:05:11.000 +07:00 - 2001-02-03 04:05:11.000 +07:00    reconcile divergent operations    args: jj op log --reversed    [EOF]    ");     // Should work correctly with `--limit`    let output = work_dir.run_jj(["op", "log", "--reversed", "--limit=3"]);    insta::assert_snapshot!(output, @r"    ○  8e3e726be123 test-username@host.example.com 2001-02-03 04:05:10.000 +07:00 - 2001-02-03 04:05:10.000 +07:00    │  describe commit 230dd059e1b059aefc0da06a2e5a7dbf22362f22    │  args: jj describe -m 'description 1' --at-op @-    │ ○  d009cfc04993 test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00    ├─╯  describe commit 230dd059e1b059aefc0da06a2e5a7dbf22362f22    │    args: jj describe -m 'description 0'    @  e4538ffdc13d test-username@host.example.com 2001-02-03 04:05:11.000 +07:00 - 2001-02-03 04:05:11.000 +07:00       reconcile divergent operations       args: jj op log --reversed    [EOF]    ");     // Should work correctly with `--limit` and `--no-graph`    let output = work_dir.run_jj(["op", "log", "--reversed", "--limit=2", "--no-graph"]);    insta::assert_snapshot!(output, @r"    d009cfc04993 test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00    describe commit 230dd059e1b059aefc0da06a2e5a7dbf22362f22    args: jj describe -m 'description 0'    e4538ffdc13d test-username@host.example.com 2001-02-03 04:05:11.000 +07:00 - 2001-02-03 04:05:11.000 +07:00    reconcile divergent operations    args: jj op log --reversed    [EOF]    ");} #[test]fn test_op_log_no_graph_null_terminated() {    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", "message1"]).success();    work_dir.run_jj(["commit", "-m", "message2"]).success();     let output = work_dir        .run_jj([            "op",            "log",            "--no-graph",            "--template",            r#"id.short(4) ++ "\0""#,        ])        .success();    insta::assert_debug_snapshot!(output.stdout.normalized(), @r#""ef17\0f412\0eac7\00000\0""#);} #[test]fn test_op_log_template() {    let test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");    let render = |template| work_dir.run_jj(["op", "log", "-T", template]);     insta::assert_snapshot!(render(r#"id ++ "\n""#), @r"    @  eac759b9ab75793fd3da96e60939fb48f2cd2b2a9c1f13ffe723cf620f3005b8d3e7e923634a07ea39513e4f2f360c87b9ad5d331cf90d7a844864b83b72eba1    ○  00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000    [EOF]    ");    insta::assert_snapshot!(        render(r#"separate(" ", id.short(5), current_operation, user,                                time.start(), time.end(), time.duration()) ++ "\n""#), @r"    @  eac75 true test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 2001-02-03 04:05:07.000 +07:00 less than a microsecond    ○  00000 false @ 1970-01-01 00:00:00.000 +00:00 1970-01-01 00:00:00.000 +00:00 less than a microsecond    [EOF]    ");     // Negative length shouldn't cause panic.    insta::assert_snapshot!(render(r#"id.short(-1) ++ "|""#), @r"    @  <Error: out of range integral type conversion attempted>|    ○  <Error: out of range integral type conversion attempted>|    [EOF]    ");     // Test the default template, i.e. with relative start time and duration. We    // don't generally use that template because it depends on the current time,    // so we need to reset the time range format here.    test_env.add_config(        r#"[template-aliases]'format_time_range(time_range)' = 'time_range.end().ago() ++ ", lasted " ++ time_range.duration()'        "#,    );    let regex = Regex::new(r"\d\d years").unwrap();    let output = work_dir.run_jj(["op", "log"]);    insta::assert_snapshot!(        output.normalize_stdout_with(|s| regex.replace_all(&s, "NN years").into_owned()), @r"    @  eac759b9ab75 test-username@host.example.com NN years ago, lasted less than a microsecond    │  add workspace 'default'    ○  000000000000 root()    [EOF]    ");} #[test]fn test_op_log_builtin_templates() {    let test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");    // Render without graph to test line ending    let render = |template| work_dir.run_jj(["op", "log", "-T", template, "--no-graph"]);    work_dir        .run_jj(["describe", "-m", "description 0"])        .success();     insta::assert_snapshot!(render(r#"builtin_op_log_compact"#), @r"    d009cfc04993 test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00    describe commit 230dd059e1b059aefc0da06a2e5a7dbf22362f22    args: jj describe -m 'description 0'    eac759b9ab75 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]    ");     insta::assert_snapshot!(render(r#"builtin_op_log_comfortable"#), @r"    d009cfc04993 test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00    describe commit 230dd059e1b059aefc0da06a2e5a7dbf22362f22    args: jj describe -m 'description 0'     eac759b9ab75 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]    ");     insta::assert_snapshot!(render(r#"builtin_op_log_oneline"#), @r"    d009cfc04993 test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00 describe commit 230dd059e1b059aefc0da06a2e5a7dbf22362f22 args: jj describe -m 'description 0'    eac759b9ab75 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_op_log_word_wrap() {    let test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();    let work_dir = test_env.work_dir("repo");    work_dir.write_file("file1", "foo\n".repeat(100));    work_dir.run_jj(["debug", "snapshot"]).success();     let render = |args: &[&str], columns: u32, word_wrap: bool| {        let word_wrap = to_toml_value(word_wrap);        work_dir.run_jj_with(|cmd| {            cmd.args(args)                .arg(format!("--config=ui.log-word-wrap={word_wrap}"))                .env("COLUMNS", columns.to_string())        })    };     // ui.log-word-wrap option works    insta::assert_snapshot!(render(&["op", "log"], 40, false), @r"    @  b7cd3d0069f6 test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00    │  snapshot working copy    │  args: jj debug snapshot    ○  eac759b9ab75 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]    ");    insta::assert_snapshot!(render(&["op", "log"], 40, true), @r"    @  b7cd3d0069f6    │  test-username@host.example.com    │  2001-02-03 04:05:08.000 +07:00 -    │  2001-02-03 04:05:08.000 +07:00    │  snapshot working copy    │  args: jj debug snapshot    ○  eac759b9ab75    │  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]    ");     // Nested graph should be wrapped    insta::assert_snapshot!(render(&["op", "log", "--op-diff"], 40, true), @r"    @  b7cd3d0069f6    │  test-username@host.example.com    │  2001-02-03 04:05:08.000 +07:00 -    │  2001-02-03 04:05:08.000 +07:00    │  snapshot working copy    │  args: jj debug snapshot    │    │  Changed commits:    │  ○  + qpvuntsm e292def1 (no    │     description set)    │     - qpvuntsm hidden 230dd059 (empty)    │     (no description set)    │    │  Changed working copy default@:    │  + qpvuntsm e292def1 (no description    │  set)    │  - qpvuntsm hidden 230dd059 (empty)    │  (no description set)    ○  eac759b9ab75    │  test-username@host.example.com    │  2001-02-03 04:05:07.000 +07:00 -    │  2001-02-03 04:05:07.000 +07:00

Lines 1–500 of 2537.