2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2022 The Jujutsu Authors
|
2022-04-23 18:34:40 +00:00
|
|
|
//
|
|
|
|
// 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;
|
|
|
|
|
2023-05-21 07:17:39 +00:00
|
|
|
use itertools::Itertools;
|
2023-01-07 03:43:46 +00:00
|
|
|
use regex::Regex;
|
|
|
|
|
2023-03-05 04:10:02 +00:00
|
|
|
use crate::common::{get_stdout_string, TestEnvironment};
|
2022-04-23 18:34:40 +00:00
|
|
|
|
|
|
|
pub mod common;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_op_log() {
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
2022-12-12 11:43:28 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "description 0"]);
|
2022-04-23 18:34:40 +00:00
|
|
|
|
2023-02-16 03:19:41 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
&repo_path,
|
2023-02-16 03:26:31 +00:00
|
|
|
&[
|
|
|
|
"op",
|
|
|
|
"log",
|
|
|
|
"--config-toml",
|
2023-02-19 08:05:50 +00:00
|
|
|
"template-aliases.'format_time_range(x)' = 'x'",
|
2023-02-16 03:26:31 +00:00
|
|
|
],
|
2023-02-16 03:19:41 +00:00
|
|
|
);
|
2022-11-22 17:11:40 +00:00
|
|
|
insta::assert_snapshot!(&stdout, @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ 45108169c0f8 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'
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ a99a3fd5c51e test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
|
2023-02-09 02:53:47 +00:00
|
|
|
│ add workspace 'default'
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 56b94dfc38e7 test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
|
2023-02-09 02:53:47 +00:00
|
|
|
initialize repo
|
2022-04-23 18:34:40 +00:00
|
|
|
"###);
|
2023-05-21 07:17:39 +00:00
|
|
|
let op_log_lines = stdout.lines().collect_vec();
|
|
|
|
let add_workspace_id = op_log_lines[3].split(' ').nth(2).unwrap();
|
|
|
|
let initialize_repo_id = op_log_lines[5].split(' ').nth(2).unwrap();
|
2022-04-23 18:34:40 +00:00
|
|
|
|
|
|
|
// Can load the repo at a specific operation ID
|
2022-12-12 11:43:28 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path, initialize_repo_id), @r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 0000000000000000000000000000000000000000
|
2022-04-28 23:32:18 +00:00
|
|
|
"###);
|
2022-12-12 11:43:28 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path, add_workspace_id), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 0000000000000000000000000000000000000000
|
2022-04-23 18:34:40 +00:00
|
|
|
"###);
|
|
|
|
// "@" resolves to the head operation
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path, "@"), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ bc8f18aa6f396a93572811632313cbb5625d475d
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 0000000000000000000000000000000000000000
|
2022-04-23 18:34:40 +00:00
|
|
|
"###);
|
2022-04-20 05:51:52 +00:00
|
|
|
// "@-" resolves to the parent of the head operation
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path, "@-"), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 0000000000000000000000000000000000000000
|
2022-04-20 05:51:52 +00:00
|
|
|
"###);
|
2022-12-12 11:18:06 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path, "@--"), @r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 0000000000000000000000000000000000000000
|
2022-12-12 11:18:06 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(
|
|
|
|
test_env.jj_cmd_failure(&repo_path, &["log", "--at-op", "@---"]), @r###"
|
|
|
|
Error: The "@---" expression resolved to no operations
|
|
|
|
"###);
|
|
|
|
// "ID-" also resolves to the parent.
|
|
|
|
insta::assert_snapshot!(
|
|
|
|
get_log_output(&test_env, &repo_path, &format!("{add_workspace_id}-")), @r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 0000000000000000000000000000000000000000
|
2022-12-12 11:18:06 +00:00
|
|
|
"###);
|
2022-04-23 18:34:40 +00:00
|
|
|
|
|
|
|
// We get a reasonable message if an invalid operation ID is specified
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(test_env.jj_cmd_failure(&repo_path, &["log", "--at-op", "foo"]), @r###"
|
|
|
|
Error: Operation ID "foo" is not a valid hexadecimal prefix
|
|
|
|
"###);
|
2022-04-23 18:34:40 +00:00
|
|
|
// Odd length
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(test_env.jj_cmd_failure(&repo_path, &["log", "--at-op", "123456789"]), @r###"
|
|
|
|
Error: No operation ID matching "123456789"
|
|
|
|
"###);
|
2022-04-23 18:34:40 +00:00
|
|
|
// Even length
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(test_env.jj_cmd_failure(&repo_path, &["log", "--at-op", "0123456789"]), @r###"
|
|
|
|
Error: No operation ID matching "0123456789"
|
|
|
|
"###);
|
2022-04-23 18:34:40 +00:00
|
|
|
// Empty ID
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(test_env.jj_cmd_failure(&repo_path, &["log", "--at-op", ""]), @r###"
|
|
|
|
Error: Operation ID "" is not a valid hexadecimal prefix
|
|
|
|
"###);
|
2022-04-20 05:51:52 +00:00
|
|
|
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "description 1"]);
|
|
|
|
test_env.jj_cmd_success(
|
|
|
|
&repo_path,
|
|
|
|
&[
|
|
|
|
"describe",
|
|
|
|
"-m",
|
|
|
|
"description 2",
|
|
|
|
"--at-op",
|
2022-12-12 11:43:28 +00:00
|
|
|
add_workspace_id,
|
2022-04-20 05:51:52 +00:00
|
|
|
],
|
|
|
|
);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(test_env.jj_cmd_failure(&repo_path, &["log", "--at-op", "@-"]), @r###"
|
|
|
|
Error: The "@-" expression resolved to more than one operation
|
|
|
|
"###);
|
2022-04-20 05:51:52 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["st"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(test_env.jj_cmd_failure(&repo_path, &["log", "--at-op", "@-"]), @r###"
|
|
|
|
Error: The "@-" expression resolved to more than one operation
|
|
|
|
"###);
|
2022-04-23 18:34:40 +00:00
|
|
|
}
|
|
|
|
|
2023-02-19 09:15:54 +00:00
|
|
|
#[test]
|
|
|
|
fn test_op_log_template() {
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
let render = |template| test_env.jj_cmd_success(&repo_path, &["op", "log", "-T", template]);
|
|
|
|
|
2023-02-28 11:30:57 +00:00
|
|
|
insta::assert_snapshot!(render(r#"id ++ "\n""#), @r###"
|
2023-02-19 09:15:54 +00:00
|
|
|
@ a99a3fd5c51e8f7ccb9ae2f9fb749612a23f0a7cf25d8c644f36c35c077449ce3c66f49d098a5a704ca5e47089a7f019563a5b8cbc7d451619e0f90c82241ceb
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 56b94dfc38e7d54340377f566e96ab97dc6163ea7841daf49fb2e1d1ceb27e26274db1245835a1a421fb9d06e6e0fe1e4f4aa1b0258c6e86df676ad9111d0dab
|
2023-02-19 09:15:54 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(
|
|
|
|
render(r#"separate(" ", id.short(5), current_operation, user,
|
2023-02-28 11:30:57 +00:00
|
|
|
time.start(), time.end(), time.duration()) ++ "\n""#), @r###"
|
2023-02-19 09:15:54 +00:00
|
|
|
@ a99a3 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
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 56b94 false 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
|
2023-02-19 09:15:54 +00:00
|
|
|
"###);
|
2023-04-08 00:34:12 +00:00
|
|
|
// 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.start().ago() ++ ", lasted " ++ time_range.duration()'
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
let regex = Regex::new(r"\d\d years").unwrap();
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]);
|
|
|
|
insta::assert_snapshot!(regex.replace_all(&stdout, "NN years"), @r###"
|
|
|
|
@ a99a3fd5c51e test-username@host.example.com NN years ago, lasted less than a microsecond
|
|
|
|
│ add workspace 'default'
|
|
|
|
◉ 56b94dfc38e7 test-username@host.example.com NN years ago, lasted less than a microsecond
|
|
|
|
initialize repo
|
|
|
|
"###);
|
2023-02-19 09:15:54 +00:00
|
|
|
}
|
|
|
|
|
2023-04-13 17:30:48 +00:00
|
|
|
#[test]
|
|
|
|
fn test_op_log_builtin_templates() {
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
let render = |template| test_env.jj_cmd_success(&repo_path, &["op", "log", "-T", template]);
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "description 0"]);
|
|
|
|
|
|
|
|
insta::assert_snapshot!(render(r#"builtin_op_log_compact"#), @r###"
|
|
|
|
@ 45108169c0f8 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'
|
|
|
|
◉ a99a3fd5c51e 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'
|
|
|
|
◉ 56b94dfc38e7 test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
|
|
|
|
initialize repo
|
|
|
|
"###);
|
|
|
|
|
|
|
|
insta::assert_snapshot!(render(r#"builtin_op_log_comfortable"#), @r###"
|
|
|
|
@ 45108169c0f8 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'
|
|
|
|
│
|
|
|
|
◉ a99a3fd5c51e 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'
|
|
|
|
│
|
|
|
|
◉ 56b94dfc38e7 test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
|
|
|
|
initialize repo
|
|
|
|
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2023-03-05 04:10:02 +00:00
|
|
|
#[test]
|
|
|
|
fn test_op_log_word_wrap() {
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
let render = |args: &[&str], columns: u32, word_wrap: bool| {
|
|
|
|
let mut args = args.to_vec();
|
|
|
|
if word_wrap {
|
|
|
|
args.push("--config-toml=ui.log-word-wrap=true");
|
|
|
|
}
|
|
|
|
let assert = test_env
|
|
|
|
.jj_cmd(&repo_path, &args)
|
|
|
|
.env("COLUMNS", columns.to_string())
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stderr("");
|
|
|
|
get_stdout_string(&assert)
|
|
|
|
};
|
|
|
|
|
|
|
|
// ui.log-word-wrap option works
|
|
|
|
insta::assert_snapshot!(render(&["op", "log"], 40, false), @r###"
|
2023-04-08 00:34:12 +00:00
|
|
|
@ a99a3fd5c51e test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
|
2023-03-05 04:10:02 +00:00
|
|
|
│ add workspace 'default'
|
2023-04-08 00:34:12 +00:00
|
|
|
◉ 56b94dfc38e7 test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
|
2023-03-05 04:10:02 +00:00
|
|
|
initialize repo
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(render(&["op", "log"], 40, true), @r###"
|
|
|
|
@ a99a3fd5c51e
|
2023-04-08 00:34:12 +00:00
|
|
|
│ test-username@host.example.com
|
|
|
|
│ 2001-02-03 04:05:07.000 +07:00 -
|
|
|
|
│ 2001-02-03 04:05:07.000 +07:00
|
2023-03-05 04:10:02 +00:00
|
|
|
│ add workspace 'default'
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 56b94dfc38e7
|
2023-04-08 00:34:12 +00:00
|
|
|
test-username@host.example.com
|
|
|
|
2001-02-03 04:05:07.000 +07:00 -
|
|
|
|
2001-02-03 04:05:07.000 +07:00
|
2023-03-05 04:10:02 +00:00
|
|
|
initialize repo
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2022-11-13 06:29:06 +00:00
|
|
|
#[test]
|
|
|
|
fn test_op_log_configurable() {
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.add_config(
|
2023-01-26 19:26:18 +00:00
|
|
|
r#"operation.hostname = "my-hostname"
|
2022-11-13 06:29:06 +00:00
|
|
|
operation.username = "my-username"
|
|
|
|
"#,
|
|
|
|
);
|
2022-11-14 07:41:11 +00:00
|
|
|
test_env
|
2022-11-22 17:11:40 +00:00
|
|
|
.jj_cmd(test_env.env_root(), &["init", "repo", "--git"])
|
2022-11-14 07:41:11 +00:00
|
|
|
.env_remove("JJ_OP_HOSTNAME")
|
|
|
|
.env_remove("JJ_OP_USERNAME")
|
|
|
|
.assert()
|
|
|
|
.success();
|
2022-11-13 06:29:06 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]);
|
|
|
|
assert!(stdout.contains("my-username@my-hostname"));
|
|
|
|
}
|
|
|
|
|
2022-04-23 18:34:40 +00:00
|
|
|
fn get_log_output(test_env: &TestEnvironment, repo_path: &Path, op_id: &str) -> String {
|
2022-10-19 05:21:25 +00:00
|
|
|
test_env.jj_cmd_success(
|
|
|
|
repo_path,
|
|
|
|
&["log", "-T", "commit_id", "--at-op", op_id, "-r", "all()"],
|
|
|
|
)
|
2022-04-23 18:34:40 +00:00
|
|
|
}
|