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

immutable commits: remove the hint if trying to edit the root commit

The hint is a bit misleading in this case. I also changed the message slightly.
This commit is contained in:
Ilya Grigoriev 2023-10-28 20:36:57 -07:00
parent ebb6b942ac
commit b482898924
3 changed files with 15 additions and 8 deletions

View file

@ -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(())

View file

@ -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

View file

@ -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
"###);
}