// 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 itertools::Itertools; use regex::Regex; use crate::common::{get_stdout_string, TestEnvironment}; #[test] fn test_op_log() { let test_env = TestEnvironment::default(); test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); let repo_path = test_env.env_root().join("repo"); test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "description 0"]); let stdout = test_env.jj_cmd_success( &repo_path, &[ "op", "log", "--config-toml", "template-aliases.'format_time_range(x)' = 'x'", ], ); insta::assert_snapshot!(&stdout, @r###" @ 52ac15d375ba 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' ◉ b51416386f26 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' ◉ 9a7d829846af 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 ◉ 000000000000 root() "###); 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(); // Can load the repo at a specific operation ID insta::assert_snapshot!(get_log_output(&test_env, &repo_path, initialize_repo_id), @r###" ◉ 0000000000000000000000000000000000000000 "###); insta::assert_snapshot!(get_log_output(&test_env, &repo_path, add_workspace_id), @r###" @ 230dd059e1b059aefc0da06a2e5a7dbf22362f22 ◉ 0000000000000000000000000000000000000000 "###); // "@" resolves to the head operation insta::assert_snapshot!(get_log_output(&test_env, &repo_path, "@"), @r###" @ bc8f18aa6f396a93572811632313cbb5625d475d ◉ 0000000000000000000000000000000000000000 "###); // "@-" resolves to the parent of the head operation insta::assert_snapshot!(get_log_output(&test_env, &repo_path, "@-"), @r###" @ 230dd059e1b059aefc0da06a2e5a7dbf22362f22 ◉ 0000000000000000000000000000000000000000 "###); insta::assert_snapshot!( test_env.jj_cmd_failure(&repo_path, &["log", "--at-op", "@----"]), @r###" Error: The "@----" expression resolved to no operations "###); // We get a reasonable message if an invalid operation ID is specified 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 "###); test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "description 1"]); test_env.jj_cmd_ok( &repo_path, &[ "describe", "-m", "description 2", "--at-op", add_workspace_id, ], ); insta::assert_snapshot!(test_env.jj_cmd_failure(&repo_path, &["log", "--at-op", "@-"]), @r###" Error: The "@" expression resolved to more than one operation "###); } #[test] fn test_op_log_with_custom_symbols() { let test_env = TestEnvironment::default(); test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); let repo_path = test_env.env_root().join("repo"); test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "description 0"]); let stdout = test_env.jj_cmd_success( &repo_path, &[ "op", "log", "--config-toml", concat!( "template-aliases.'format_time_range(x)' = 'x'\n", "templates.op_log_node = 'if(current_operation, \"$\", if(root, \"┴\", \"┝\"))'", ), ], ); insta::assert_snapshot!(&stdout, @r###" $ 52ac15d375ba 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' ┝ b51416386f26 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' ┝ 9a7d829846af 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 ┴ 000000000000 root() "###); } #[test] fn test_op_log_with_no_template() { let test_env = TestEnvironment::default(); test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); let repo_path = test_env.env_root().join("repo"); let stderr = test_env.jj_cmd_cli_error(&repo_path, &["op", "log", "-T"]); insta::assert_snapshot!(stderr, @r###" error: a value is required for '--template