ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: hint for same change ids

This commit is contained in:
Willian Mori 2023-09-17 09:41:33 -03:00 committed by Willian Mori
parent 15e2cc22ce
commit 4894636d10
2 changed files with 31 additions and 3 deletions

View file

@ -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 <REVISION>`."#,
)
} else if let RevsetExpression::CommitRef(RevsetCommitRef::Symbol(branch_name)) =
revset_expression.as_ref()
{
// Separate hint if there's a conflicted branch
format!(

View file

@ -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])