diff --git a/src/commands/debug.rs b/src/commands/debug.rs index 5a6e6b05c..a6c881098 100644 --- a/src/commands/debug.rs +++ b/src/commands/debug.rs @@ -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())?; } diff --git a/tests/test_debug_command.rs b/tests/test_debug_command.rs index e26bb559b..a783f2491 100644 --- a/tests/test_debug_command.rs +++ b/tests/test_debug_command.rs @@ -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()