From ff592e522fee1aa80d7d6717e678323dfae5fe6f Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Mon, 23 Jan 2023 21:41:11 -0800 Subject: [PATCH] edit: explicitly check that target commit is rewritable I think the CLI should check if the target of `jj edit` is rewritable before calling the library to update the repo. The other commands already do that. Then, if calling `MutableRepo::edit()` fails, it's always an internal error, which makes error handling simpler in coming commits. --- src/cli_util.rs | 2 +- src/commands/mod.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cli_util.rs b/src/cli_util.rs index 775a5dcfb..6154f85a0 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -113,7 +113,7 @@ impl From for CommandError { impl From for CommandError { fn from(err: RewriteRootCommit) -> Self { - user_error(err.to_string()) + CommandError::InternalError(format!("Attempted to rewrite the root commit: {err}")) } } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index f0405f9b1..4183fbb6f 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1964,6 +1964,7 @@ fn cmd_abandon( fn cmd_edit(ui: &mut Ui, command: &CommandHelper, args: &EditArgs) -> Result<(), CommandError> { let mut workspace_command = command.workspace_helper(ui)?; let new_commit = workspace_command.resolve_single_rev(&args.revision)?; + workspace_command.check_rewriteable(&new_commit)?; let workspace_id = workspace_command.workspace_id(); if workspace_command .repo()