Skip to content

Commit

Permalink
cli: hint for same change ids
Browse files Browse the repository at this point in the history
  • Loading branch information
wmrmrx committed Sep 22, 2023
1 parent ef55110 commit b2ccc89
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <REVISION>"."#,
)
} else if let RevsetExpression::CommitRef(RevsetCommitRef::Symbol(branch_name)) =
revset_expression.as_ref()
{
// Separate hint if there's a conflicted branch
format!(
Expand Down
22 changes: 22 additions & 0 deletions cli/tests/test_checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <REVISION>".
"###);
}

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])
Expand Down

0 comments on commit b2ccc89

Please sign in to comment.