From 65a525cfd957a0bbe1c7aaa3bf209f13b5bb5118 Mon Sep 17 00:00:00 2001 From: Evan Mesterhazy Date: Thu, 11 Apr 2024 14:02:12 -0400 Subject: [PATCH] Add a test for splitting the parent of a merge commit without `--siblings` This is the same as the `test_split_siblings_with_merge_child` added in https://github.com/martinvonz/jj/pull/3485, but without the siblings flag. I forgot to add the non-siblings version in that PR. #3485 --- cli/tests/test_split_command.rs | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/cli/tests/test_split_command.rs b/cli/tests/test_split_command.rs index 81bc878140..a4b19be6f0 100644 --- a/cli/tests/test_split_command.rs +++ b/cli/tests/test_split_command.rs @@ -250,6 +250,49 @@ JJ: Lines starting with "JJ: " (like this one) will be removed. "###); } +// This test makes sure that the children of the commit being split retain any +// other parents which weren't involved in the split. +#[test] +fn test_split_with_merge_child() { + let mut test_env = TestEnvironment::default(); + test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); + let workspace_path = test_env.env_root().join("repo"); + test_env.jj_cmd_ok(&workspace_path, &["describe", "-m=1"]); + test_env.jj_cmd_ok(&workspace_path, &["new", "root()", "-m=a"]); + std::fs::write(workspace_path.join("file1"), "foo\n").unwrap(); + std::fs::write(workspace_path.join("file2"), "bar\n").unwrap(); + test_env.jj_cmd_ok( + &workspace_path, + &["new", "description(1)", "description(a)", "-m=2"], + ); + insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###" + @ zsuskulnrvyr true 2 + ├─╮ + │ ◉ kkmpptxzrspx false a + ◉ │ qpvuntsmwlqt true 1 + ├─╯ + ◉ zzzzzzzzzzzz true + "###); + + // Set up the editor and do the split. + let edit_script = test_env.set_up_fake_editor(); + std::fs::write( + edit_script, + ["write\nAdd file1", "next invocation\n", "write\nAdd file2"].join("\0"), + ) + .unwrap(); + test_env.jj_cmd_ok(&workspace_path, &["split", "-r", "description(a)", "file1"]); + insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###" + @ zsuskulnrvyr true 2 + ├─╮ + │ ◉ royxmykxtrkr false Add file2 + │ ◉ kkmpptxzrspx false Add file1 + ◉ │ qpvuntsmwlqt true 1 + ├─╯ + ◉ zzzzzzzzzzzz true + "###); +} + #[test] // Split a commit with no descendants into siblings. Also tests that the default // description is set correctly on the first commit.