// 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; use crate::common::strip_last_line; use crate::common::TestEnvironment; #[test] fn test_op_log() { 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, &["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#" @ 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() "#); let op_log_lines = stdout.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(&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###" @ 19611c995a342c01f525583e5fcafdd211f6d009 ◆ 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 "###); let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log", "--op-diff"]); insta::assert_snapshot!(&stdout, @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: │ ○ Change qpvuntsmwlqt │ + 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: │ ○ Change qpvuntsmwlqt │ + qpvuntsm 230dd059 (empty) (no description set) ○ 000000000000 root() "#); 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 Hint: Try specifying one of the operations by ID: fd29e648380b, 3e8ef7115a0c "#); } #[test] fn test_op_log_with_custom_symbols() { 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, &["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#" $ 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() "#); } #[test] fn test_op_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, &["op", "log", "-T"]); insta::assert_snapshot!(stderr, @r#" error: a value is required for '--template