Skip to content

Commit

Permalink
tests: add additional test case for jj simplify-parents
Browse files Browse the repository at this point in the history
This test shows that the current implementation of `jj simplify-parents`
perform unnecessary rebases of descendant commits.
  • Loading branch information
bnjmnt4n committed Nov 22, 2024
1 parent c6bb019 commit 1ae8f0c
Showing 1 changed file with 75 additions and 1 deletion.
76 changes: 75 additions & 1 deletion cli/tests/test_simplify_parents_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, @"");
Expand All @@ -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
"#);
}

0 comments on commit 1ae8f0c

Please sign in to comment.