From cc7e20859c36970d3979f4145f193be75e6632c0 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Fri, 22 Apr 2022 21:17:38 -0700 Subject: [PATCH] tests: add tests of `jj move` to ancestor, showing lost branch I noticed earlier today that branches get lost (stuck on a hidden commit) when you move part of a change to an ancestor. This patch adds tests for both of those cases, showing the bug. There's no special logic for this case in the CLI crate, so we should be able to test it in the library crate instead, but since I have already written the tests, maybe we can keep them. --- tests/test_move_command.rs | 51 +++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/tests/test_move_command.rs b/tests/test_move_command.rs index 74ddd069c..7e9b57e39 100644 --- a/tests/test_move_command.rs +++ b/tests/test_move_command.rs @@ -129,6 +129,29 @@ fn test_move() { let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2"]); insta::assert_snapshot!(stdout, @"f "); + + // Can move from descendant + test_env.jj_cmd_success(&repo_path, &["undo"]); + let stdout = test_env.jj_cmd_success(&repo_path, &["move", "--from", "e", "--to", "d"]); + insta::assert_snapshot!(stdout, @r###" + Rebased 1 descendant commits + Working copy now at: 2b723b1d6033 + "###); + // The change has been removed from the source (the change pointed to by 'e' + // became empty and was abandoned) + insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" + @ 2b723b1d6033 f + o 4293930d6333 d e + | o caa4d0b23201 c + | o 55171e33db26 b + |/ + o 3db0a2f5b535 a + o 000000000000 + "###); + // The change from the source has been applied + let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2", "-r", "d"]); + insta::assert_snapshot!(stdout, @"e +"); } #[test] @@ -225,7 +248,7 @@ fn test_move_partial() { insta::assert_snapshot!(stdout, @"d "); - // Can move only part of the change in non-interactive mode + // Can move only part of the change from a sibling in non-interactive mode test_env.jj_cmd_success(&repo_path, &["undo"]); // Clear the script so we know it won't be used std::fs::write(&edit_script, "").unwrap(); @@ -254,6 +277,32 @@ fn test_move_partial() { let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file3"]); insta::assert_snapshot!(stdout, @"d "); + + // Can move only part of the change from a descendant in non-interactive mode + test_env.jj_cmd_success(&repo_path, &["undo"]); + // Clear the script so we know it won't be used + std::fs::write(&edit_script, "").unwrap(); + let stdout = + test_env.jj_cmd_success(&repo_path, &["move", "--from", "c", "--to", "b", "file1"]); + insta::assert_snapshot!(stdout, @"Rebased 1 descendant commits +"); + // TODO: The 'c' branch got lost + insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" + o 21253406d416 + o e1cf08aae711 b + | @ bdd835cae844 d + |/ + o 3db0a2f5b535 a + o 000000000000 + "###); + // The selected change from the source has been applied + let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1", "-r", "b"]); + insta::assert_snapshot!(stdout, @"c +"); + // The unselected change from the source has not been applied + let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2", "-r", "b"]); + insta::assert_snapshot!(stdout, @"a +"); } fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {