// 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 std::path::PathBuf; use itertools::Itertools as _; use regex::Regex; use testutils::git; use crate::common::to_toml_value; use crate::common::CommandOutput; use crate::common::TestEnvironment; use crate::common::TestWorkDir; #[test] fn test_op_log() { 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", "description 0"]) .success(); let output = work_dir.run_jj(["op", "log"]); insta::assert_snapshot!(output, @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() [EOF] "); let op_log_lines = output.stdout.raw().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(&work_dir, add_workspace_id), @r" @ 230dd059e1b059aefc0da06a2e5a7dbf22362f22 ◆ 0000000000000000000000000000000000000000 [EOF] "); // "@" resolves to the head operation insta::assert_snapshot!(get_log_output(&work_dir, "@"), @r" @ 19611c995a342c01f525583e5fcafdd211f6d009 ◆ 0000000000000000000000000000000000000000 [EOF] "); // "@-" resolves to the parent of the head operation insta::assert_snapshot!(get_log_output(&work_dir, "@-"), @r" @ 230dd059e1b059aefc0da06a2e5a7dbf22362f22 ◆ 0000000000000000000000000000000000000000 [EOF] "); insta::assert_snapshot!(work_dir.run_jj(["log", "--at-op", "@---"]), @r#" ------- stderr ------- Error: The "@---" expression resolved to no operations [EOF] [exit status: 1] "#); // We get a reasonable message if an invalid operation ID is specified insta::assert_snapshot!(work_dir.run_jj(["log", "--at-op", "foo"]), @r#" ------- stderr ------- Error: Operation ID "foo" is not a valid hexadecimal prefix [EOF] [exit status: 1] "#); let output = work_dir.run_jj(["op", "log", "--op-diff"]); insta::assert_snapshot!(output, @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: │ ○ + qpvuntsm 19611c99 (empty) description 0 │ - qpvuntsm hidden 230dd059 (empty) (no description set) │ │ Changed working copy default@: │ + 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: │ ○ + qpvuntsm 230dd059 (empty) (no description set) │ │ Changed working copy default@: │ + qpvuntsm 230dd059 (empty) (no description set) │ - (absent) ○ 000000000000 root() [EOF] "); work_dir .run_jj(["describe", "-m", "description 1"]) .success(); work_dir .run_jj([ "describe", "-m", "description 2", "--at-op", add_workspace_id, ]) .success(); insta::assert_snapshot!(work_dir.run_jj(["log", "--at-op", "@-"]), @r#" ------- stderr ------- Error: The "@" expression resolved to more than one operation Hint: Try specifying one of the operations by ID: fd29e648380b, 3e8ef7115a0c [EOF] [exit status: 1] "#); } #[test] fn test_op_log_with_custom_symbols() { 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", "description 0"]) .success(); let output = work_dir.run_jj([ "op", "log", "--config=templates.op_log_node='if(current_operation, \"$\", if(root, \"┴\", \"┝\"))'", ]); insta::assert_snapshot!(output, @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() [EOF] "); } #[test] fn test_op_log_with_no_template() { 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(["op", "log", "-T"]); insta::assert_snapshot!(output, @r" ------- stderr ------- error: a value is required for '--template