From 9aa5af793241314b5f192898531d7a1c8a25baf8 Mon Sep 17 00:00:00 2001 From: Essien Ita Essien <34972+essiene@users.noreply.github.com> Date: Thu, 25 Jul 2024 09:10:41 +0100 Subject: [PATCH] Add unittests for changes to fix #4147 * Rename existing test * Add new tests * Also update Changelog here --- CHANGELOG.md | 4 ++ cli/tests/test_status_command.rs | 75 +++++++++++++++++++++++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1444c566ba..c990b7075d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -101,6 +101,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Fixed bugs +* `jj status` will show different messages in a conflicted tree, depending + on the state of the working commit. In particular, if a child commit has + fixed the conflict, this will be reflected in the hint provided by `jj status` + * `jj diff --git` no longer shows the contents of binary files. * Windows binaries no longer require `vcruntime140.dll` to be installed diff --git a/cli/tests/test_status_command.rs b/cli/tests/test_status_command.rs index 81bb9e03728..8edd4977462 100644 --- a/cli/tests/test_status_command.rs +++ b/cli/tests/test_status_command.rs @@ -106,7 +106,7 @@ fn test_status_filtered() { // See #[test] -fn test_status_display_rebase_instructions() { +fn test_status_display_rebase_instructions_if_no_decendant_resolves_conflict() { let test_env = TestEnvironment::default(); test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]); @@ -177,6 +177,79 @@ fn test_status_display_rebase_instructions() { "###); } +#[test] +fn test_status_display_if_child_resolves_conflict() { + let test_env = TestEnvironment::default(); + test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]); + + let repo_path = test_env.env_root().join("repo"); + let conflicted_path = repo_path.join("conflicted.txt"); + + // PARENT: Write the initial file + std::fs::write(&conflicted_path, "initial contents").unwrap(); + test_env.jj_cmd_ok(&repo_path, &["describe", "--message", "Initial contents"]); + + // CHILD1: New commit on top of + test_env.jj_cmd_ok( + &repo_path, + &["new", "--message", "First part of conflicting change"], + ); + std::fs::write(&conflicted_path, "Child 1").unwrap(); + + // CHILD2: New commit also on top of + test_env.jj_cmd_ok( + &repo_path, + &[ + "new", + "--message", + "Second part of conflicting change", + "@-", + ], + ); + std::fs::write(&conflicted_path, "Child 2").unwrap(); + + // CONFLICT: New commit that is conflicted by merging and + test_env.jj_cmd_ok(&repo_path, &["new", "--message", "boom", "all:(@-)+"]); + // Adding more descendants to ensure we correctly find the root ancestors with + // conflicts, not just the parents. + test_env.jj_cmd_ok(&repo_path, &["new", "--message", "boom-cont"]); + test_env.jj_cmd_ok(&repo_path, &["new", "--message", "boom-cont-2"]); + std::fs::write(&conflicted_path, "resolved conflict").unwrap(); + + let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "::@"]); + + insta::assert_snapshot!(stdout, @r###" + @ yqosqzyt test.user@example.com 2001-02-03 08:05:13 65143fef conflict + │ (empty) boom-cont-2 + × royxmykx test.user@example.com 2001-02-03 08:05:12 a4e88714 conflict + │ (empty) boom-cont + × mzvwutvl test.user@example.com 2001-02-03 08:05:11 538415e7 conflict + ├─╮ (empty) boom + │ ○ kkmpptxz test.user@example.com 2001-02-03 08:05:10 1e8c2956 + │ │ First part of conflicting change + ○ │ zsuskuln test.user@example.com 2001-02-03 08:05:11 2c8b19fd + ├─╯ Second part of conflicting change + ○ qpvuntsm test.user@example.com 2001-02-03 08:05:08 aade7195 + │ Initial contents + ◆ zzzzzzzz root() 00000000 + "###); + + let stdout = test_env.jj_cmd_success(&repo_path, &["status"]); + + insta::assert_snapshot!(stdout, @r###" + The working copy is clean + There are unresolved conflicts at these paths: + conflicted.txt 2-sided conflict + Working copy : yqosqzyt 65143fef (conflict) (empty) boom-cont-2 + Parent commit: royxmykx a4e88714 (conflict) (empty) boom-cont + To resolve the conflicts, start by updating to the first one: + jj new mzvwutvlkqwt + Then use `jj resolve`, or edit the conflict markers in the file directly. + Once the conflicts are resolved, you may want to inspect the result with `jj diff`. + Then run `jj squash` to move the resolution into the conflicted commit. + "###); +} + #[test] fn test_status_simplify_conflict_sides() { let test_env = TestEnvironment::default();