use crate::common::TestEnvironment;
#[test]
fn test_rewrite_immutable_generic() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file"), "a").unwrap();
test_env.jj_cmd_ok(&repo_path, &["describe", "-m=a"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m=b"]);
std::fs::write(repo_path.join("file"), "b").unwrap();
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_ok(&repo_path, &["new", "main-", "-m=c"]);
std::fs::write(repo_path.join("file"), "c").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["log"]);
insta::assert_snapshot!(stdout, @r###"
@ mzvwutvl test.user@example.com 2001-02-03 04:05:12.000 +07:00 78ebd449
│ c
│ ◉ kkmpptxz test.user@example.com 2001-02-03 04:05:10.000 +07:00 main c8d4c7ca
├─╯ b
◉ qpvuntsm test.user@example.com 2001-02-03 04:05:08.000 +07:00 46a8dc51
│ a
◉ zzzzzzzz root() 00000000
"###);
test_env.add_config(r#"revset-aliases."immutable_heads()" = "main""#);
let stderr = test_env.jj_cmd_failure(&repo_path, &["edit", "main"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit c8d4c7ca95d0 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["edit", "main-"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 46a8dc5175be is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
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: The root commit 000000000000 is immutable
"###);
test_env.add_config(r#"revset-aliases."immutable_heads(foo)" = "none()""#);
let stderr = test_env.jj_cmd_failure(&repo_path, &["edit", "root()"]);
insta::assert_snapshot!(stderr, @r###"
Config error: Invalid `revsets.short-prefixes`: --> 1:31
|
1 | @ | ancestors(immutable_heads().., 2) | heads(immutable_heads())
| ^
|
= Invalid arguments to revset function "immutable_heads": Expected 1 arguments
For help, see https://github.com/martinvonz/jj/blob/main/docs/config.md.
"###);
test_env.add_config(r#"revsets.short-prefixes = "immutable_heads(root())""#);
let stderr = test_env.jj_cmd_failure(&repo_path, &["edit", "root()"]);
insta::assert_snapshot!(stderr, @r###"
Error: The `revset-aliases.immutable_heads()` function must be declared without arguments.
"###);
}
#[test]
fn test_rewrite_immutable_commands() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file"), "a").unwrap();
test_env.jj_cmd_ok(&repo_path, &["describe", "-m=a"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m=b"]);
std::fs::write(repo_path.join("file"), "b").unwrap();
test_env.jj_cmd_ok(&repo_path, &["new", "@-", "-m=c"]);
std::fs::write(repo_path.join("file"), "c").unwrap();
test_env.jj_cmd_ok(&repo_path, &["new", "all:visible_heads()", "-m=merge"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_ok(&repo_path, &["new", "description(b)"]);
test_env.add_config(r#"revset-aliases."immutable_heads()" = "main""#);
let stdout = test_env.jj_cmd_success(&repo_path, &["log"]);
insta::assert_snapshot!(stdout, @r###"
@ yqosqzyt test.user@example.com 2001-02-03 04:05:13.000 +07:00 3f89addf
│ (empty) (no description set)
│ ◉ mzvwutvl test.user@example.com 2001-02-03 04:05:11.000 +07:00 main 16ca9d80 conflict
╭─┤ (empty) merge
│ │
│ ~
│
◉ kkmpptxz test.user@example.com 2001-02-03 04:05:10.000 +07:00 c8d4c7ca
│ b
~
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["abandon", "main"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 16ca9d800b08 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["chmod", "-r=main", "x", "file"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 16ca9d800b08 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["describe", "main"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 16ca9d800b08 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["diffedit", "-r=main"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 16ca9d800b08 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["edit", "main"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 16ca9d800b08 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["move", "--from=main"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 16ca9d800b08 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["move", "--to=main"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 16ca9d800b08 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["new", "--insert-before", "main"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 16ca9d800b08 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["new", "--insert-after", "description(b)"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 16ca9d800b08 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["rebase", "-s=main", "-d=@"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 16ca9d800b08 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["rebase", "-b=main", "-d=@"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 6e11f430f297 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["rebase", "-r=main", "-d=@"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 16ca9d800b08 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["resolve", "-r=description(merge)", "file"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 16ca9d800b08 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["restore", "-c=main"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 16ca9d800b08 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["restore", "--to=main"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 16ca9d800b08 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["split", "-r=main"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 16ca9d800b08 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["squash", "-r=main"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 16ca9d800b08 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["unsquash", "-r=main"]);
insta::assert_snapshot!(stderr, @r###"
Error: Commit 16ca9d800b08 is immutable
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
}