diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index c22adaeec2..5afdf8c66a 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -1022,9 +1022,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 a0aa817966..9c359d14e1 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])