1684 lines · 51.4 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 crate::common::get_stdout_string;use crate::common::TestEnvironment; #[test]fn test_log_with_empty_revision() {    let test_env = TestEnvironment::default();    test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);    let repo_path = test_env.env_root().join("repo");     let stderr = test_env.jj_cmd_cli_error(&repo_path, &["log", "-r="]);    insta::assert_snapshot!(stderr, @r###"    error: a value is required for '--revisions <REVISIONS>' but none was supplied     For more information, try '--help'.    "###);} #[test]fn test_log_with_no_template() {    let test_env = TestEnvironment::default();    test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);    let repo_path = test_env.env_root().join("repo");     let stderr = test_env.jj_cmd_cli_error(&repo_path, &["log", "-T"]);    insta::assert_snapshot!(stderr, @r#"    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_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    - commit_summary_separator    - description_placeholder    - email_placeholder    - name_placeholder    "#);} #[test]fn test_log_with_or_without_diff() {    let test_env = TestEnvironment::default();    test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);    let repo_path = test_env.env_root().join("repo");     std::fs::write(repo_path.join("file1"), "foo\n").unwrap();    test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "add a file"]);    test_env.jj_cmd_ok(&repo_path, &["new", "-m", "a new commit"]);    std::fs::write(repo_path.join("file1"), "foo\nbar\n").unwrap();     let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description"]);    insta::assert_snapshot!(stdout, @r###"    @  a new commit    ○  add a file    ◆    "###);     let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "-p"]);    insta::assert_snapshot!(stdout, @r###"    @  a new commit    │  Modified regular file file1:    │     1    1: foo    │          2: bar    ○  add a file    │  Added regular file file1:    │          1: foo    ◆    "###);     let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "--no-graph"]);    insta::assert_snapshot!(stdout, @r###"    a new commit    add a file    "###);     // `-p` for default diff output, `-s` for summary    let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "-p", "-s"]);    insta::assert_snapshot!(stdout, @r###"    @  a new commit    │  M file1    │  Modified regular file file1:    │     1    1: foo    │          2: bar    ○  add a file    │  A file1    │  Added regular file file1:    │          1: foo    ◆    "###);     // `-s` for summary, `--git` for git diff (which implies `-p`)    let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "-s", "--git"]);    insta::assert_snapshot!(stdout, @r###"    @  a new commit    │  M file1    │  diff --git a/file1 b/file1    │  index 257cc5642c..3bd1f0e297 100644    │  --- a/file1    │  +++ b/file1    │  @@ -1,1 +1,2 @@    │   foo    │  +bar    ○  add a file    │  A file1    │  diff --git a/file1 b/file1    │  new file mode 100644    │  index 0000000000..257cc5642c    │  --- /dev/null    │  +++ b/file1    │  @@ -1,0 +1,1 @@    │  +foo    ◆    "###);     // `-p` enables default "summary" output, so `-s` is noop    let stdout = test_env.jj_cmd_success(        &repo_path,        &[            "log",            "-T",            "description",            "-p",            "-s",            "--config-toml=ui.diff.format='summary'",        ],    );    insta::assert_snapshot!(stdout, @r###"    @  a new commit    │  M file1    ○  add a file    │  A file1    ◆    "###);     // `-p` enables default "color-words" diff output, so `--color-words` is noop    let stdout = test_env.jj_cmd_success(        &repo_path,        &["log", "-T", "description", "-p", "--color-words"],    );    insta::assert_snapshot!(stdout, @r###"    @  a new commit    │  Modified regular file file1:    │     1    1: foo    │          2: bar    ○  add a file    │  Added regular file file1:    │          1: foo    ◆    "###);     // `--git` enables git diff, so `-p` is noop    let stdout = test_env.jj_cmd_success(        &repo_path,        &["log", "-T", "description", "--no-graph", "-p", "--git"],    );    insta::assert_snapshot!(stdout, @r###"    a new commit    diff --git a/file1 b/file1    index 257cc5642c..3bd1f0e297 100644    --- a/file1    +++ b/file1    @@ -1,1 +1,2 @@     foo    +bar    add a file    diff --git a/file1 b/file1    new file mode 100644    index 0000000000..257cc5642c    --- /dev/null    +++ b/file1    @@ -1,0 +1,1 @@    +foo    "###);     // Cannot use both `--git` and `--color-words`    let stderr = test_env.jj_cmd_cli_error(        &repo_path,        &[            "log",            "-T",            "description",            "--no-graph",            "-p",            "--git",            "--color-words",        ],    );    insta::assert_snapshot!(stderr, @r###"    error: the argument '--git' cannot be used with '--color-words'     Usage: jj log --template <TEMPLATE> --no-graph --patch --git [PATHS]...     For more information, try '--help'.    "###);     // `-s` with or without graph    let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "-s"]);    insta::assert_snapshot!(stdout, @r###"    @  a new commit    │  M file1    ○  add a file    │  A file1    ◆    "###);    let stdout = test_env.jj_cmd_success(        &repo_path,        &["log", "-T", "description", "--no-graph", "-s"],    );    insta::assert_snapshot!(stdout, @r###"    a new commit    M file1    add a file    A file1    "###);     // `--git` implies `-p`, with or without graph    let stdout = test_env.jj_cmd_success(        &repo_path,        &["log", "-T", "description", "-r", "@", "--git"],    );    insta::assert_snapshot!(stdout, @r###"    @  a new commit    │  diff --git a/file1 b/file1    ~  index 257cc5642c..3bd1f0e297 100644       --- a/file1       +++ b/file1       @@ -1,1 +1,2 @@        foo       +bar    "###);    let stdout = test_env.jj_cmd_success(        &repo_path,        &["log", "-T", "description", "-r", "@", "--no-graph", "--git"],    );    insta::assert_snapshot!(stdout, @r###"    a new commit    diff --git a/file1 b/file1    index 257cc5642c..3bd1f0e297 100644    --- a/file1    +++ b/file1    @@ -1,1 +1,2 @@     foo    +bar    "###);     // `--color-words` implies `-p`, with or without graph    let stdout = test_env.jj_cmd_success(        &repo_path,        &["log", "-T", "description", "-r", "@", "--color-words"],    );    insta::assert_snapshot!(stdout, @r###"    @  a new commit    │  Modified regular file file1:    ~     1    1: foo               2: bar    "###);    let stdout = test_env.jj_cmd_success(        &repo_path,        &[            "log",            "-T",            "description",            "-r",            "@",            "--no-graph",            "--color-words",        ],    );    insta::assert_snapshot!(stdout, @r###"    a new commit    Modified regular file file1:       1    1: foo            2: bar    "###);} #[test]fn test_log_null_terminate_multiline_descriptions() {    let test_env = TestEnvironment::default();    test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);    let repo_path = test_env.env_root().join("repo");     test_env.jj_cmd_ok(        &repo_path,        &["commit", "-m", "commit 1 line 1", "-m", "commit 1 line 2"],    );    test_env.jj_cmd_ok(        &repo_path,        &["commit", "-m", "commit 2 line 1", "-m", "commit 2 line 2"],    );    test_env.jj_cmd_ok(        &repo_path,        &["describe", "-m", "commit 3 line 1", "-m", "commit 3 line 2"],    );     let stdout = test_env.jj_cmd_success(        &repo_path,        &[            "log",            "-r",            "~root()",            "-T",            r#"description ++ "\0""#,            "--no-graph",        ],    );    insta::assert_debug_snapshot!(        stdout,        @r###""commit 3 line 1\n\ncommit 3 line 2\n\0commit 2 line 1\n\ncommit 2 line 2\n\0commit 1 line 1\n\ncommit 1 line 2\n\0""###    );} #[test]fn test_log_shortest_accessors() {    let test_env = TestEnvironment::default();    test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);    let repo_path = test_env.env_root().join("repo");    let render = |rev, template| {        test_env.jj_cmd_success(            &repo_path,            &["log", "--no-graph", "-r", rev, "-T", template],        )    };    test_env.add_config(        r#"        [template-aliases]        'format_id(id)' = 'id.shortest(12).prefix() ++ "[" ++ id.shortest(12).rest() ++ "]"'        "#,    );     std::fs::write(repo_path.join("file"), "original file\n").unwrap();    test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "initial"]);    test_env.jj_cmd_ok(&repo_path, &["bookmark", "c", "original"]);    insta::assert_snapshot!(        render("original", r#"format_id(change_id) ++ " " ++ format_id(commit_id)"#),        @"q[pvuntsmwlqt] e[0e22b9fae75]");     // Create a chain of 10 commits    for i in 1..10 {        test_env.jj_cmd_ok(&repo_path, &["new", "-m", &format!("commit{i}")]);        std::fs::write(repo_path.join("file"), format!("file {i}\n")).unwrap();    }    // Create 2^3 duplicates of the chain    for _ in 0..3 {        test_env.jj_cmd_ok(&repo_path, &["duplicate", "description(commit)"]);    }     insta::assert_snapshot!(        render("original", r#"format_id(change_id) ++ " " ++ format_id(commit_id)"#),        @"qpv[untsmwlqt] e0[e22b9fae75]");     insta::assert_snapshot!(        render("::@", r#"change_id.shortest() ++ " " ++ commit_id.shortest() ++ "\n""#),        @r###"    wq ed    km ef3    kp af    zn 23    yo b87    vr 1e    yq 34    ro cc    mz 1b    qpv e0    zzz 00    "###);     insta::assert_snapshot!(        render("::@", r#"format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""#),        @r###"    wq[nwkozpkust] ed[e204633421]    km[kuslswpqwq] ef3[d013266cd]    kp[qxywonksrl] af[95b841712d]    zn[kkpsqqskkl] 23[c1103d3427]    yo[stqsxwqrlt] b87[aa9b24921]    vr[uxwmqvtpmx] 1e[a31a205ce9]    yq[osqzytrlsw] 34[befb94f4eb]    ro[yxmykxtrkr] cc[0c127948ef]    mz[vwutvlkqwt] 1b[7b715afc3f]    qpv[untsmwlqt] e0[e22b9fae75]    zzz[zzzzzzzzz] 00[0000000000]    "###);     // Can get shorter prefixes in configured revset    test_env.add_config(r#"revsets.short-prefixes = "(@----)::""#);    insta::assert_snapshot!(        render("::@", r#"format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""#),        @r###"    w[qnwkozpkust] ed[e204633421]    km[kuslswpqwq] ef[3d013266cd]    kp[qxywonksrl] a[f95b841712d]    z[nkkpsqqskkl] 2[3c1103d3427]    y[ostqsxwqrlt] b[87aa9b24921]    vr[uxwmqvtpmx] 1e[a31a205ce9]    yq[osqzytrlsw] 34[befb94f4eb]    ro[yxmykxtrkr] cc[0c127948ef]    mz[vwutvlkqwt] 1b[7b715afc3f]    qpv[untsmwlqt] e0[e22b9fae75]    zzz[zzzzzzzzz] 00[0000000000]    "###);     // Can disable short prefixes by setting to empty string    test_env.add_config(r#"revsets.short-prefixes = """#);    insta::assert_snapshot!(        render("::@", r#"format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""#),        @r###"    wq[nwkozpkust] ed[e204633421]    km[kuslswpqwq] ef3[d013266cd]    kp[qxywonksrl] af[95b841712d]    zn[kkpsqqskkl] 23c[1103d3427]    yo[stqsxwqrlt] b87[aa9b24921]    vr[uxwmqvtpmx] 1e[a31a205ce9]    yq[osqzytrlsw] 34[befb94f4eb]    ro[yxmykxtrkr] cc[0c127948ef]    mz[vwutvlkqwt] 1b[7b715afc3f]    qpv[untsmwlqt] e0[e22b9fae75]    zzz[zzzzzzzzz] 00[0000000000]    "###);} #[test]fn test_log_bad_short_prefixes() {    let test_env = TestEnvironment::default();    test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);    let repo_path = test_env.env_root().join("repo");     // Suppress warning in the commit summary template    test_env.add_config("template-aliases.'format_short_id(id)' = 'id.short(8)'");     // Error on bad config of short prefixes    test_env.add_config(r#"revsets.short-prefixes = "!nval!d""#);    let stderr = test_env.jj_cmd_failure(&repo_path, &["status"]);    insta::assert_snapshot!(stderr,        @r###"    Config error: Invalid `revsets.short-prefixes`    Caused by:  --> 1:1      |    1 | !nval!d      | ^---      |      = expected <identifier> or <expression>    For help, see https://martinvonz.github.io/jj/latest/config/.    "###);     // Warn on resolution of short prefixes    test_env.add_config("revsets.short-prefixes = 'missing'");    let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["log", "-Tcommit_id.shortest()"]);    insta::assert_snapshot!(stdout, @r#"    @  2    ◆  0    "#);    insta::assert_snapshot!(stderr, @r#"    Warning: In template expression     --> 1:11      |    1 | commit_id.shortest()      |           ^------^      |      = Failed to load short-prefixes index    Failed to resolve short-prefixes disambiguation revset    Revision "missing" doesn't exist    "#);     // Error on resolution of short prefixes    test_env.add_config("revsets.short-prefixes = 'missing'");    let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r0"]);    insta::assert_snapshot!(stderr, @r#"    Error: Failed to resolve short-prefixes disambiguation revset    Caused by: Revision "missing" doesn't exist    "#);} #[test]fn test_log_prefix_highlight_styled() {    let test_env = TestEnvironment::default();    test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);    let repo_path = test_env.env_root().join("repo"); 

Lines 1–500 of 1684.