From 5a1b325f0e440e27ce17dc87b1c93d494637d80f Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Tue, 3 Dec 2024 21:02:49 -0800 Subject: [PATCH] rebase: add tests of rebasing empty sets As these tests show, we sometimes print an error when trying to rebase an empty set, and sometimes we don't say anything at all. It seems to me like we should say "Nothing changed" in all of these cases. --- cli/tests/test_rebase_command.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/cli/tests/test_rebase_command.rs b/cli/tests/test_rebase_command.rs index 14ee9ee5e6..f2dc4b1a27 100644 --- a/cli/tests/test_rebase_command.rs +++ b/cli/tests/test_rebase_command.rs @@ -115,6 +115,29 @@ fn test_rebase_invalid() { "###); } +#[test] +fn test_rebase_empty_sets() { + let test_env = TestEnvironment::default(); + test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]); + let repo_path = test_env.env_root().join("repo"); + + create_commit(&test_env, &repo_path, "a", &[]); + create_commit(&test_env, &repo_path, "b", &["a"]); + + // TODO: Make all of these say "Nothing changed"? + let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-r=none()", "-d=b"]); + insta::assert_snapshot!(stdout, @""); + insta::assert_snapshot!(stderr, @""); + let stderr = test_env.jj_cmd_failure(&repo_path, &["rebase", "-s=none()", "-d=b"]); + insta::assert_snapshot!(stderr, @r###"Error: Revset "none()" didn't resolve to any revisions"###); + let stderr = test_env.jj_cmd_failure(&repo_path, &["rebase", "-b=none()", "-d=b"]); + insta::assert_snapshot!(stderr, @r###"Error: Revset "none()" didn't resolve to any revisions"###); + // Empty because "b..a" is empty + let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-b=a", "-d=b"]); + insta::assert_snapshot!(stdout, @""); + insta::assert_snapshot!(stderr, @""); +} + #[test] fn test_rebase_bookmark() { let test_env = TestEnvironment::default();