From 1ae8f0c77acb46873728dc6c677c8a5572281e70 Mon Sep 17 00:00:00 2001 From: Benjamin Tan Date: Wed, 13 Nov 2024 23:29:56 +0800 Subject: [PATCH] tests: add additional test case for `jj simplify-parents` This test shows that the current implementation of `jj simplify-parents` perform unnecessary rebases of descendant commits. --- cli/tests/test_simplify_parents_command.rs | 76 +++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/cli/tests/test_simplify_parents_command.rs b/cli/tests/test_simplify_parents_command.rs index 0bec50e34..52995ca6d 100644 --- a/cli/tests/test_simplify_parents_command.rs +++ b/cli/tests/test_simplify_parents_command.rs @@ -157,7 +157,6 @@ fn test_simplify_parents_redundant_parent(args: &[&str]) { ◆ "###); } - let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, args); insta::allow_duplicates! { insta::assert_snapshot!(stdout, @""); @@ -178,3 +177,78 @@ fn test_simplify_parents_redundant_parent(args: &[&str]) { "###); } } + +#[test] +fn test_simplify_parents_multiple_redundant_parents() { + let (test_env, repo_path) = create_repo(); + + create_commit(&test_env, &repo_path, "a", &["root()"]); + create_commit(&test_env, &repo_path, "b", &["a"]); + create_commit(&test_env, &repo_path, "c", &["a", "b"]); + create_commit(&test_env, &repo_path, "d", &["c"]); + create_commit(&test_env, &repo_path, "e", &["d"]); + create_commit(&test_env, &repo_path, "f", &["d", "e"]); + let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "all()", "-T", "description"]); + insta::assert_snapshot!(stdout, @r#" + @ f + ├─╮ + │ ○ e + ├─╯ + ○ d + ○ c + ├─╮ + │ ○ b + ├─╯ + ○ a + ◆ + "#); + let setup_opid = test_env.current_operation_id(&repo_path); + + // Test with `-r`. + let (stdout, stderr) = + test_env.jj_cmd_ok(&repo_path, &["simplify-parents", "-r", "c", "-r", "f"]); + insta::assert_snapshot!(stdout, @""); + // TODO: The output should indicate that edges were removed from 2 commits + // (c, f) and 2 descendant commits were rebased (d, e). + insta::assert_snapshot!(stderr, @r#" + Removed 2 edges from 2 out of 2 commits. + Rebased 3 descendant commits + Working copy now at: kmkuslsw 8cc01e1b f | f + Parent commit : znkkpsqq 040ae3a6 e | e + "#); + + let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "all()", "-T", "description"]); + insta::assert_snapshot!(stdout, @r#" + @ f + ○ e + ○ d + ○ c + ○ b + ○ a + ◆ + "#); + + // Test with `-s`. + test_env.jj_cmd_ok(&repo_path, &["op", "restore", &setup_opid]); + let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["simplify-parents", "-s", "c"]); + insta::assert_snapshot!(stdout, @""); + // TODO: The output should indicate that edges were removed from 2 commits + // (c, f) and 2 descendant commits were rebased (d, e). + insta::assert_snapshot!(stderr, @r#" + Removed 2 edges from 2 out of 4 commits. + Rebased 3 descendant commits + Working copy now at: kmkuslsw 70a39dff f | f + Parent commit : znkkpsqq a021fee9 e | e + "#); + + let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "all()", "-T", "description"]); + insta::assert_snapshot!(stdout, @r#" + @ f + ○ e + ○ d + ○ c + ○ b + ○ a + ◆ + "#); +}