From 910c73a9ae751e676ef60d9539c461c1427e542d Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Mon, 30 Jan 2023 20:08:17 -0800 Subject: [PATCH] tests: demonstrate bug on undo after squash in colocated working copy I think this is the same bug as reported in #922, just simplified a bit further. The branches in the repo actually look good after the `undo` operation, but the reverted `master` branch doesn't get exported to the git repo even though our recorded `refs/heads/master` in the repo was moved back. Then the next automatic import on `log` notices that the `master` branch in the git repo still points to the new commit, and that commit becomes visible again. --- tests/test_git_colocated.rs | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/test_git_colocated.rs b/tests/test_git_colocated.rs index 7002efa49..903558471 100644 --- a/tests/test_git_colocated.rs +++ b/tests/test_git_colocated.rs @@ -266,6 +266,49 @@ fn test_git_colocated_fetch_deleted_branch() { "###); } +#[test] +fn test_git_colocated_squash_undo() { + let test_env = TestEnvironment::default(); + let repo_path = test_env.env_root().join("repo"); + git2::Repository::init(&repo_path).unwrap(); + test_env.jj_cmd_success(&repo_path, &["init", "--git-repo=."]); + test_env.jj_cmd_success(&repo_path, &["ci", "-m=A"]); + // Test the setup + insta::assert_snapshot!(get_log_output_divergence(&test_env, &repo_path), @r###" + @ 8e4fac809cbb 8f71e3b6a3be (no description set) + o 9a45c67d3e96 a86754f975f9 A master + o 000000000000 000000000000 (no description set) + "###); + + test_env.jj_cmd_success(&repo_path, &["squash"]); + insta::assert_snapshot!(get_log_output_divergence(&test_env, &repo_path), @r###" + @ 0757f5ec8418 f0c12b0396d9 (no description set) + o 9a45c67d3e96 2f376ea1478c A master + o 000000000000 000000000000 (no description set) + "###); + test_env.jj_cmd_success(&repo_path, &["undo"]); + // TODO: There should be no divergence here; 2f376ea1478c should be hidden + // (#922) + insta::assert_snapshot!(get_log_output_divergence(&test_env, &repo_path), @r###" + o 9a45c67d3e96 2f376ea1478c A master !divergence! + | @ 8e4fac809cbb 8f71e3b6a3be (no description set) + | o 9a45c67d3e96 a86754f975f9 A !divergence! + |/ + o 000000000000 000000000000 (no description set) + "###); +} + +fn get_log_output_divergence(test_env: &TestEnvironment, repo_path: &Path) -> String { + test_env.jj_cmd_success( + repo_path, + &[ + "log", + "-T", + r#"change_id.short() " " commit_id.short() " " description.first_line() " " branches if(divergent, " !divergence!")"#, + ], + ) +} + fn get_log_output(test_env: &TestEnvironment, workspace_root: &Path) -> String { test_env.jj_cmd_success( workspace_root,