Skip to content

Commit

Permalink
immutable commits: remove the hint if trying to edit the root commit
Browse files Browse the repository at this point in the history
The hint is a bit misleading in this case. I also changed the message slightly.
  • Loading branch information
ilyagr committed Oct 30, 2023
1 parent b2f2995 commit 2190aee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
17 changes: 13 additions & 4 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1268,10 +1268,19 @@ Set which revision the branch points to with `jj branch set {branch_name} -r <RE
let revset = self.evaluate_revset(to_rewrite_revset.intersection(&immutable_revset))?;
if let Some(commit) = revset.iter().commits(self.repo().store()).next() {
let commit = commit?;
return Err(user_error_with_hint(
format!("Commit {} is immutable", short_commit_hash(commit.id()),),
"Configure the set of immutable commits via `revset-aliases.immutable_heads()`.",
));
let error = if commit.id() == self.repo().store().root_commit_id() {
user_error(format!(
"The root commit {} is immutable",
short_commit_hash(commit.id()),
))
} else {
user_error_with_hint(
format!("Commit {} is immutable", short_commit_hash(commit.id()),),
"Configure the set of immutable commits via \
`revset-aliases.immutable_heads()`.",
)
};
return Err(error);
}

Ok(())
Expand Down
3 changes: 1 addition & 2 deletions cli/tests/test_immutable_commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ fn test_rewrite_immutable_generic() {
test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#);
let stderr = test_env.jj_cmd_failure(&repo_path, &["edit", "root()"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 000000000000 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
Error: The root commit 000000000000 is immutable
"###);
// Error if we redefine immutable_heads() with an argument
// TODO: This error comes from the built-in definition of
Expand Down
3 changes: 1 addition & 2 deletions cli/tests/test_new_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,7 @@ fn test_new_insert_before_root() {
let stderr =
test_env.jj_cmd_failure(&repo_path, &["new", "--insert-before", "-m", "G", "root()"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 000000000000 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
Error: The root commit 000000000000 is immutable
"###);
}

Expand Down

0 comments on commit 2190aee

Please sign in to comment.