Skip to content

Commit 4894636

Browse files
committed
cli: hint for same change ids
1 parent 15e2cc2 commit 4894636

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

cli/src/cli_util.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,9 +1021,15 @@ impl WorkspaceCommandHelper {
10211021
.map(|c| self.format_commit_summary(c))
10221022
.join("\n")
10231023
+ elided.then_some("\n...").unwrap_or_default();
1024-
let hint = if let RevsetExpression::CommitRef(RevsetCommitRef::Symbol(
1025-
branch_name,
1026-
)) = revset_expression.as_ref()
1024+
let hint = if commits[0].change_id() == commits[1].change_id() {
1025+
// Separate hint if there's commits with same change id
1026+
format!(
1027+
r#"The revset "{revision_str}" resolved to these revisions:
1028+
{commits_summary}
1029+
Some of these commits have the same change id. Abandon one of them with `jj abandon -r <REVISION>`."#,
1030+
)
1031+
} else if let RevsetExpression::CommitRef(RevsetCommitRef::Symbol(branch_name)) =
1032+
revset_expression.as_ref()
10271033
{
10281034
// Separate hint if there's a conflicted branch
10291035
format!(

cli/tests/test_checkout.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,28 @@ fn test_checkout_conflicting_branches() {
135135
"###);
136136
}
137137

138+
#[test]
139+
fn test_checkout_conflicting_change_ids() {
140+
let test_env = TestEnvironment::default();
141+
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
142+
let repo_path = test_env.env_root().join("repo");
143+
144+
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "one"]);
145+
test_env.jj_cmd_success(&repo_path, &["--at-op=@-", "describe", "-m", "two"]);
146+
147+
// Trigger resolution of concurrent operations
148+
test_env.jj_cmd_success(&repo_path, &["st"]);
149+
150+
let stderr = test_env.jj_cmd_failure(&repo_path, &["checkout", "qpvuntsm"]);
151+
insta::assert_snapshot!(stderr, @r###"
152+
Error: Revset "qpvuntsm" resolved to more than one revision
153+
Hint: The revset "qpvuntsm" resolved to these revisions:
154+
qpvuntsm d2ae6806 (empty) two
155+
qpvuntsm a9330854 (empty) one
156+
Some of these commits have the same change id. Abandon one of them with `jj abandon -r <REVISION>`.
157+
"###);
158+
}
159+
138160
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
139161
let template = r#"commit_id ++ " " ++ description"#;
140162
test_env.jj_cmd_success(cwd, &["log", "-T", template])

0 commit comments

Comments
 (0)