ok/jj
1
0
Fork 0
forked from mirrors/jj

jj debug operation --display id option to show current operation id for tests

I also considered `jj operation id`, but I'm not sure this is useful outside tests
This commit is contained in:
Ilya Grigoriev 2023-06-06 17:57:19 -07:00
parent 14e19d0692
commit fa1e961f53
2 changed files with 19 additions and 0 deletions

View file

@ -75,6 +75,8 @@ pub struct DebugOperationArgs {
pub enum DebugOperationDisplay {
/// Show only the operation details.
Operation,
/// Show the operation id only
Id,
/// Show only the view details
View,
/// Show both the view and the operation
@ -158,6 +160,10 @@ pub fn cmd_debug(
DebugCommands::Operation(operation_args) => {
let workspace_command = command.workspace_helper(ui)?;
let op = workspace_command.resolve_single_op(&operation_args.operation)?;
if operation_args.display == DebugOperationDisplay::Id {
writeln!(ui, "{}", op.id().hex())?;
return Ok(());
}
if operation_args.display != DebugOperationDisplay::View {
writeln!(ui, "{:#?}", op.store_operation())?;
}

View file

@ -118,6 +118,19 @@ fn test_debug_reindex() {
);
}
#[test]
fn test_debug_operation_id() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
let workspace_path = test_env.env_root().join("repo");
let stdout =
test_env.jj_cmd_success(&workspace_path, &["debug", "operation", "--display", "id"]);
assert_snapshot!(filter_index_stats(&stdout), @r###"
a99a3fd5c51e8f7ccb9ae2f9fb749612a23f0a7cf25d8c644f36c35c077449ce3c66f49d098a5a704ca5e47089a7f019563a5b8cbc7d451619e0f90c82241ceb
"###
);
}
fn filter_index_stats(text: &str) -> String {
let regex = Regex::new(r" Name: [0-9a-z]+").unwrap();
regex.replace_all(text, " Name: [hash]").to_string()