1695 lines · 67.9 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 indoc::indoc;use regex::Regex;use testutils::git; use crate::common::TestEnvironment; #[test]fn test_log_parents() {    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"]).success();    work_dir.run_jj(["new", "@-"]).success();    work_dir.run_jj(["new", "@", "@-"]).success();     let template =        r#"commit_id ++ "\nP: " ++ parents.len() ++ " " ++ parents.map(|c| c.commit_id()) ++ "\n""#;    let output = work_dir.run_jj(["log", "-T", template]);    insta::assert_snapshot!(output, @r"    @    8b93ef7a3ceefa4e4b1a506945588dd0da2d9e3e    ├─╮  P: 2 1c1c95df80e53b1e654608d7589f5baabb10ebb2 e8849ae12c709f2321908879bc724fdb2ab8a781    ○ │  1c1c95df80e53b1e654608d7589f5baabb10ebb2    ├─╯  P: 1 e8849ae12c709f2321908879bc724fdb2ab8a781    ○  e8849ae12c709f2321908879bc724fdb2ab8a781    │  P: 1 0000000000000000000000000000000000000000    ◆  0000000000000000000000000000000000000000       P: 0    [EOF]    ");     // List<Commit> can be filtered    let template =        r#""P: " ++ parents.filter(|c| !c.root()).map(|c| c.commit_id().short()) ++ "\n""#;    let output = work_dir.run_jj(["log", "-T", template]);    insta::assert_snapshot!(output, @r"    @    P: 1c1c95df80e5 e8849ae12c70    ├─╮    ○ │  P: e8849ae12c70    ├─╯    ○  P:    ◆  P:    [EOF]    ");     let template = r#"parents.map(|c| c.commit_id().shortest(4))"#;    let output = work_dir.run_jj(["log", "-T", template, "-r@", "--color=always"]);    insta::assert_snapshot!(output, @r"    @  1c1c e884    │    ~    [EOF]    ");     // Commit object isn't printable    let output = work_dir.run_jj(["log", "-T", "parents"]);    insta::assert_snapshot!(output, @r"    ------- stderr -------    Error: Failed to parse template: Expected expression of type `Template`, but actual type is `List<Commit>`    Caused by:  --> 1:1      |    1 | parents      | ^-----^      |      = Expected expression of type `Template`, but actual type is `List<Commit>`    [EOF]    [exit status: 1]    ");     // Redundant argument passed to keyword method    let template = r#"parents.map(|c| c.commit_id(""))"#;    let output = work_dir.run_jj(["log", "-T", template]);    insta::assert_snapshot!(output, @r#"    ------- stderr -------    Error: Failed to parse template: Function `commit_id`: Expected 0 arguments    Caused by:  --> 1:29      |    1 | parents.map(|c| c.commit_id(""))      |                             ^^      |      = Function `commit_id`: Expected 0 arguments    [EOF]    [exit status: 1]    "#);} #[test]fn test_log_author_timestamp() {    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", "first"]).success();    work_dir.run_jj(["new", "-m", "second"]).success();     let output = work_dir.run_jj(["log", "-T", "author.timestamp()"]);    insta::assert_snapshot!(output, @r"    @  2001-02-03 04:05:09.000 +07:00    ○  2001-02-03 04:05:08.000 +07:00    ◆  1970-01-01 00:00:00.000 +00:00    [EOF]    ");} #[test]fn test_log_author_timestamp_ago() {    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", "first"]).success();    work_dir.run_jj(["new", "-m", "second"]).success();     let template = r#"author.timestamp().ago() ++ "\n""#;    let output = work_dir        .run_jj(&["log", "--no-graph", "-T", template])        .success();    let line_re = Regex::new(r"[0-9]+ years ago").unwrap();    assert!(        output.stdout.raw().lines().all(|x| line_re.is_match(x)),        "expected every line to match regex"    );} #[test]fn test_log_author_timestamp_utc() {    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(["log", "-T", "author.timestamp().utc()"]);    insta::assert_snapshot!(output, @r"    @  2001-02-02 21:05:07.000 +00:00    ◆  1970-01-01 00:00:00.000 +00:00    [EOF]    ");} #[cfg(unix)]#[test]fn test_log_author_timestamp_local() {    let mut test_env = TestEnvironment::default();    test_env.run_jj_in(".", ["git", "init", "repo"]).success();     test_env.add_env_var("TZ", "UTC-05:30");    let work_dir = test_env.work_dir("repo");    let output = work_dir.run_jj(["log", "-T", "author.timestamp().local()"]);    insta::assert_snapshot!(output, @r"    @  2001-02-03 08:05:07.000 +11:00    ◆  1970-01-01 11:00:00.000 +11:00    [EOF]    ");    test_env.add_env_var("TZ", "UTC+10:00");    let work_dir = test_env.work_dir("repo");    let output = work_dir.run_jj(["log", "-T", "author.timestamp().local()"]);    insta::assert_snapshot!(output, @r"    @  2001-02-03 08:05:07.000 +11:00    ◆  1970-01-01 11:00:00.000 +11:00    [EOF]    ");} #[test]fn test_log_author_timestamp_after_before() {    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", "first"]).success();     let template = r#"    separate(" ",      author.timestamp(),      ":",      if(author.timestamp().after("1969"), "(after 1969)", "(before 1969)"),      if(author.timestamp().before("1975"), "(before 1975)", "(after 1975)"),      if(author.timestamp().before("now"), "(before now)", "(after now)")    ) ++ "\n""#;    let output = work_dir.run_jj(["log", "--no-graph", "-T", template]);    insta::assert_snapshot!(output, @r"    2001-02-03 04:05:08.000 +07:00 : (after 1969) (after 1975) (before now)    1970-01-01 00:00:00.000 +00:00 : (after 1969) (before 1975) (before now)    [EOF]    ");     // Should display error with invalid date.    let template = r#"author.timestamp().after("invalid date")"#;    let output = work_dir.run_jj(["log", "-r@", "--no-graph", "-T", template]);    insta::assert_snapshot!(output, @r#"    ------- stderr -------    Error: Failed to parse template: Invalid date pattern    Caused by:    1:  --> 1:26      |    1 | author.timestamp().after("invalid date")      |                          ^------------^      |      = Invalid date pattern    2: expected unsupported identifier as position 0..7    [EOF]    [exit status: 1]    "#);} #[test]fn test_mine_is_true_when_author_is_user() {    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([            "--config=user.email=johndoe@example.com",            "--config=user.name=John Doe",            "new",        ])        .success();     let output = work_dir.run_jj([        "log",        "-T",        r#"coalesce(if(mine, "mine"), author.email(), email_placeholder)"#,    ]);    insta::assert_snapshot!(output, @r"    @  johndoe@example.com    ○  mine    ◆  (no email set)    [EOF]    ");} #[test]fn test_log_json() {    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", "first"]).success();    work_dir.run_jj(["new", "-m", "second"]).success();     let output = work_dir.run_jj(["log", r#"-Tjson(self) ++ "\n""#]);    insta::assert_snapshot!(output, @r#"    @  {"commit_id":"b1cb6b2f9141e6ffee18532a8bf9a2075ca02606","parents":["68a505386f936fff6d718f55005e77ea72589bc1"],"change_id":"kkmpptxzrspxrzommnulwmwkkqwworpl","description":"second\n","author":{"name":"Test User","email":"test.user@example.com","timestamp":"2001-02-03T04:05:09+07:00"},"committer":{"name":"Test User","email":"test.user@example.com","timestamp":"2001-02-03T04:05:09+07:00"}}    ○  {"commit_id":"68a505386f936fff6d718f55005e77ea72589bc1","parents":["0000000000000000000000000000000000000000"],"change_id":"qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu","description":"first\n","author":{"name":"Test User","email":"test.user@example.com","timestamp":"2001-02-03T04:05:08+07:00"},"committer":{"name":"Test User","email":"test.user@example.com","timestamp":"2001-02-03T04:05:08+07:00"}}    ◆  {"commit_id":"0000000000000000000000000000000000000000","parents":[],"change_id":"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz","description":"","author":{"name":"","email":"","timestamp":"1970-01-01T00:00:00Z"},"committer":{"name":"","email":"","timestamp":"1970-01-01T00:00:00Z"}}    [EOF]    "#);} #[test]fn test_log_default() {    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");    work_dir.run_jj(["describe", "-m", "add a file"]).success();    work_dir.run_jj(["new", "-m", "description 1"]).success();    work_dir        .run_jj(["bookmark", "create", "-r@", "my-bookmark"])        .success();     // Test default log output format    let output = work_dir.run_jj(["log"]);    insta::assert_snapshot!(output, @r"    @  kkmpptxz test.user@example.com 2001-02-03 08:05:09 my-bookmark c938c088    │  (empty) description 1    ○  qpvuntsm test.user@example.com 2001-02-03 08:05:08 007859d3    │  add a file    ◆  zzzzzzzz root() 00000000    [EOF]    ");     // Color    let output = work_dir.run_jj(["log", "--color=always"]);    insta::assert_snapshot!(output, @r"    @  kkmpptxz test.user@example.com 2001-02-03 08:05:09 my-bookmark c938c088    │  (empty) description 1    ○  qpvuntsm test.user@example.com 2001-02-03 08:05:08 007859d3    │  add a file    ◆  zzzzzzzz root() 00000000    [EOF]    ");     // Color without graph    let output = work_dir.run_jj(["log", "--color=always", "--no-graph"]);    insta::assert_snapshot!(output, @r"    kkmpptxz test.user@example.com 2001-02-03 08:05:09 my-bookmark c938c088    (empty) description 1    qpvuntsm test.user@example.com 2001-02-03 08:05:08 007859d3    add a file    zzzzzzzz root() 00000000    [EOF]    ");} #[test]fn test_log_default_without_working_copy() {    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(["workspace", "forget"]).success();    let output = work_dir.run_jj(["log"]);    insta::assert_snapshot!(output, @r"    ◆  zzzzzzzz root() 00000000    [EOF]    ");} #[test]fn test_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(["log", "-T", template, "--no-graph"]);     work_dir        .run_jj(["--config=user.email=''", "--config=user.name=''", "new"])        .success();    work_dir        .run_jj(["bookmark", "create", "-r@", "my-bookmark"])        .success();     insta::assert_snapshot!(render(r#"builtin_log_oneline"#), @r"    rlvkpnrz (no email set) 2001-02-03 08:05:08 my-bookmark aec3ec96 (empty) (no description set)    qpvuntsm test.user 2001-02-03 08:05:07 e8849ae1 (empty) (no description set)    zzzzzzzz root() 00000000    [EOF]    ");     insta::assert_snapshot!(render(r#"builtin_log_compact"#), @r"    rlvkpnrz (no email set) 2001-02-03 08:05:08 my-bookmark aec3ec96    (empty) (no description set)    qpvuntsm test.user@example.com 2001-02-03 08:05:07 e8849ae1    (empty) (no description set)    zzzzzzzz root() 00000000    [EOF]    ");     insta::assert_snapshot!(render(r#"builtin_log_comfortable"#), @r"    rlvkpnrz (no email set) 2001-02-03 08:05:08 my-bookmark aec3ec96    (empty) (no description set)     qpvuntsm test.user@example.com 2001-02-03 08:05:07 e8849ae1    (empty) (no description set)     zzzzzzzz root() 00000000     [EOF]    ");     insta::assert_snapshot!(render(r#"builtin_log_detailed"#), @r"    Commit ID: aec3ec964d0771edea9da48a2a170bc6ffa1c725    Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp    Bookmarks: my-bookmark    Author   : (no name set) <(no email set)> (2001-02-03 08:05:08)    Committer: (no name set) <(no email set)> (2001-02-03 08:05:08)         (no description set)     Commit ID: e8849ae12c709f2321908879bc724fdb2ab8a781    Change ID: qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu    Author   : Test User <test.user@example.com> (2001-02-03 08:05:07)    Committer: Test User <test.user@example.com> (2001-02-03 08:05:07)         (no description set)     Commit ID: 0000000000000000000000000000000000000000    Change ID: zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz    Author   : (no name set) <(no email set)> (1970-01-01 11:00:00)    Committer: (no name set) <(no email set)> (1970-01-01 11:00:00)         (no description set)     [EOF]    ");} #[test]fn test_log_builtin_templates_colored() {    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(["--color=always", "log", "-T", template]);     work_dir        .run_jj(["--config=user.email=''", "--config=user.name=''", "new"])        .success();    work_dir        .run_jj(["bookmark", "create", "-r@", "my-bookmark"])        .success();     insta::assert_snapshot!(render(r#"builtin_log_oneline"#), @r"    @  rlvkpnrz (no email set) 2001-02-03 08:05:08 my-bookmark aec3ec96 (empty) (no description set)    ○  qpvuntsm test.user 2001-02-03 08:05:07 e8849ae1 (empty) (no description set)    ◆  zzzzzzzz root() 00000000    [EOF]    ");     insta::assert_snapshot!(render(r#"builtin_log_compact"#), @r"    @  rlvkpnrz (no email set) 2001-02-03 08:05:08 my-bookmark aec3ec96    │  (empty) (no description set)    ○  qpvuntsm test.user@example.com 2001-02-03 08:05:07 e8849ae1    │  (empty) (no description set)    ◆  zzzzzzzz root() 00000000    [EOF]    ");     insta::assert_snapshot!(render(r#"builtin_log_comfortable"#), @r"    @  rlvkpnrz (no email set) 2001-02-03 08:05:08 my-bookmark aec3ec96    │  (empty) (no description set)    │    ○  qpvuntsm test.user@example.com 2001-02-03 08:05:07 e8849ae1    │  (empty) (no description set)    │    ◆  zzzzzzzz root() 00000000     [EOF]    ");     insta::assert_snapshot!(render(r#"builtin_log_detailed"#), @r"    @  Commit ID: aec3ec964d0771edea9da48a2a170bc6ffa1c725    │  Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp    │  Bookmarks: my-bookmark    │  Author   : (no name set) <(no email set)> (2001-02-03 08:05:08)    │  Committer: (no name set) <(no email set)> (2001-02-03 08:05:08)    │    │      (no description set)    │    ○  Commit ID: e8849ae12c709f2321908879bc724fdb2ab8a781    │  Change ID: qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu    │  Author   : Test User <test.user@example.com> (2001-02-03 08:05:07)    │  Committer: Test User <test.user@example.com> (2001-02-03 08:05:07)    │    │      (no description set)    │    ◆  Commit ID: 0000000000000000000000000000000000000000       Change ID: zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz       Author   : (no name set) <(no email set)> (1970-01-01 11:00:00)       Committer: (no name set) <(no email set)> (1970-01-01 11:00:00)            (no description set)     [EOF]    ");} #[test]fn test_log_builtin_templates_colored_debug() {    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(["--color=debug", "log", "-T", template]);     work_dir        .run_jj(["--config=user.email=''", "--config=user.name=''", "new"])        .success();    work_dir        .run_jj(["bookmark", "create", "-r@", "my-bookmark"])        .success();     insta::assert_snapshot!(render(r#"builtin_log_oneline"#), @r"    <<log commit node working_copy mutable::@>>  <<log commit working_copy mutable change_id shortest prefix::r>><<log commit working_copy mutable change_id shortest rest::lvkpnrz>><<log commit working_copy mutable:: >><<log commit working_copy mutable email placeholder::(no email set)>><<log commit working_copy mutable:: >><<log commit working_copy mutable committer timestamp local format::2001-02-03 08:05:08>><<log commit working_copy mutable:: >><<log commit working_copy mutable bookmarks name::my-bookmark>><<log commit working_copy mutable:: >><<log commit working_copy mutable commit_id shortest prefix::a>><<log commit working_copy mutable commit_id shortest rest::ec3ec96>><<log commit working_copy mutable:: >><<log commit working_copy mutable empty::(empty)>><<log commit working_copy mutable:: >><<log commit working_copy mutable empty description placeholder::(no description set)>><<log commit working_copy mutable::>>    <<log commit node mutable::○>>  <<log commit mutable change_id shortest prefix::q>><<log commit mutable change_id shortest rest::pvuntsm>><<log commit mutable:: >><<log commit mutable author email local::test.user>><<log commit mutable:: >><<log commit mutable committer timestamp local format::2001-02-03 08:05:07>><<log commit mutable:: >><<log commit mutable commit_id shortest prefix::e>><<log commit mutable commit_id shortest rest::8849ae1>><<log commit mutable:: >><<log commit mutable empty::(empty)>><<log commit mutable:: >><<log commit mutable empty description placeholder::(no description set)>><<log commit mutable::>>    <<log commit node immutable::◆>>  <<log commit immutable change_id shortest prefix::z>><<log commit immutable change_id shortest rest::zzzzzzz>><<log commit immutable:: >><<log commit immutable root::root()>><<log commit immutable:: >><<log commit immutable commit_id shortest prefix::0>><<log commit immutable commit_id shortest rest::0000000>><<log commit immutable::>>    [EOF]    ");     insta::assert_snapshot!(render(r#"builtin_log_compact"#), @r"    <<log commit node working_copy mutable::@>>  <<log commit working_copy mutable change_id shortest prefix::r>><<log commit working_copy mutable change_id shortest rest::lvkpnrz>><<log commit working_copy mutable:: >><<log commit working_copy mutable email placeholder::(no email set)>><<log commit working_copy mutable:: >><<log commit working_copy mutable committer timestamp local format::2001-02-03 08:05:08>><<log commit working_copy mutable:: >><<log commit working_copy mutable bookmarks name::my-bookmark>><<log commit working_copy mutable:: >><<log commit working_copy mutable commit_id shortest prefix::a>><<log commit working_copy mutable commit_id shortest rest::ec3ec96>><<log commit working_copy mutable::>>    │  <<log commit working_copy mutable empty::(empty)>><<log commit working_copy mutable:: >><<log commit working_copy mutable empty description placeholder::(no description set)>><<log commit working_copy mutable::>>    <<log commit node mutable::○>>  <<log commit mutable change_id shortest prefix::q>><<log commit mutable change_id shortest rest::pvuntsm>><<log commit mutable:: >><<log commit mutable author email local::test.user>><<log commit mutable author email::@>><<log commit mutable author email domain::example.com>><<log commit mutable:: >><<log commit mutable committer timestamp local format::2001-02-03 08:05:07>><<log commit mutable:: >><<log commit mutable commit_id shortest prefix::e>><<log commit mutable commit_id shortest rest::8849ae1>><<log commit mutable::>>    │  <<log commit mutable empty::(empty)>><<log commit mutable:: >><<log commit mutable empty description placeholder::(no description set)>><<log commit mutable::>>    <<log commit node immutable::◆>>  <<log commit immutable change_id shortest prefix::z>><<log commit immutable change_id shortest rest::zzzzzzz>><<log commit immutable:: >><<log commit immutable root::root()>><<log commit immutable:: >><<log commit immutable commit_id shortest prefix::0>><<log commit immutable commit_id shortest rest::0000000>><<log commit immutable::>>    [EOF]    ");     insta::assert_snapshot!(render(r#"builtin_log_comfortable"#), @r"    <<log commit node working_copy mutable::@>>  <<log commit working_copy mutable change_id shortest prefix::r>><<log commit working_copy mutable change_id shortest rest::lvkpnrz>><<log commit working_copy mutable:: >><<log commit working_copy mutable email placeholder::(no email set)>><<log commit working_copy mutable:: >><<log commit working_copy mutable committer timestamp local format::2001-02-03 08:05:08>><<log commit working_copy mutable:: >><<log commit working_copy mutable bookmarks name::my-bookmark>><<log commit working_copy mutable:: >><<log commit working_copy mutable commit_id shortest prefix::a>><<log commit working_copy mutable commit_id shortest rest::ec3ec96>><<log commit working_copy mutable::>>    │  <<log commit working_copy mutable empty::(empty)>><<log commit working_copy mutable:: >><<log commit working_copy mutable empty description placeholder::(no description set)>><<log commit working_copy mutable::>>    │  <<log commit::>>    <<log commit node mutable::○>>  <<log commit mutable change_id shortest prefix::q>><<log commit mutable change_id shortest rest::pvuntsm>><<log commit mutable:: >><<log commit mutable author email local::test.user>><<log commit mutable author email::@>><<log commit mutable author email domain::example.com>><<log commit mutable:: >><<log commit mutable committer timestamp local format::2001-02-03 08:05:07>><<log commit mutable:: >><<log commit mutable commit_id shortest prefix::e>><<log commit mutable commit_id shortest rest::8849ae1>><<log commit mutable::>>    │  <<log commit mutable empty::(empty)>><<log commit mutable:: >><<log commit mutable empty description placeholder::(no description set)>><<log commit mutable::>>    │  <<log commit::>>    <<log commit node immutable::◆>>  <<log commit immutable change_id shortest prefix::z>><<log commit immutable change_id shortest rest::zzzzzzz>><<log commit immutable:: >><<log commit immutable root::root()>><<log commit immutable:: >><<log commit immutable commit_id shortest prefix::0>><<log commit immutable commit_id shortest rest::0000000>><<log commit immutable::>>

Lines 1–500 of 1695.