From 4894636d10f02714c9dba17d26277647390560cc Mon Sep 17 00:00:00 2001 From: Willian Mori Date: Sun, 17 Sep 2023 09:41:33 -0300 Subject: [PATCH] cli: hint for same change ids --- cli/src/cli_util.rs | 12 +++++++++--- cli/tests/test_checkout.rs | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 19cb2a87d..6e71f2712 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -1021,9 +1021,15 @@ impl WorkspaceCommandHelper { .map(|c| self.format_commit_summary(c)) .join("\n") + elided.then_some("\n...").unwrap_or_default(); - let hint = if let RevsetExpression::CommitRef(RevsetCommitRef::Symbol( - branch_name, - )) = revset_expression.as_ref() + let hint = if commits[0].change_id() == commits[1].change_id() { + // Separate hint if there's commits with same change id + format!( + r#"The revset "{revision_str}" resolved to these revisions: +{commits_summary} +Some of these commits have the same change id. Abandon one of them with `jj abandon -r `."#, + ) + } else if let RevsetExpression::CommitRef(RevsetCommitRef::Symbol(branch_name)) = + revset_expression.as_ref() { // Separate hint if there's a conflicted branch format!( diff --git a/cli/tests/test_checkout.rs b/cli/tests/test_checkout.rs index a0aa81796..1777637f7 100644 --- a/cli/tests/test_checkout.rs +++ b/cli/tests/test_checkout.rs @@ -135,6 +135,28 @@ fn test_checkout_conflicting_branches() { "###); } +#[test] +fn test_checkout_conflicting_change_ids() { + let test_env = TestEnvironment::default(); + test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); + let repo_path = test_env.env_root().join("repo"); + + test_env.jj_cmd_success(&repo_path, &["describe", "-m", "one"]); + test_env.jj_cmd_success(&repo_path, &["--at-op=@-", "describe", "-m", "two"]); + + // Trigger resolution of concurrent operations + test_env.jj_cmd_success(&repo_path, &["st"]); + + let stderr = test_env.jj_cmd_failure(&repo_path, &["checkout", "qpvuntsm"]); + insta::assert_snapshot!(stderr, @r###" + Error: Revset "qpvuntsm" resolved to more than one revision + Hint: The revset "qpvuntsm" resolved to these revisions: + qpvuntsm d2ae6806 (empty) two + qpvuntsm a9330854 (empty) one + Some of these commits have the same change id. Abandon one of them with `jj abandon -r `. + "###); +} + fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String { let template = r#"commit_id ++ " " ++ description"#; test_env.jj_cmd_success(cwd, &["log", "-T", template])