mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-19 19:08:08 +00:00
cli: split single revset resolution hint to paragraphs
Perhaps, this makes it slightly easier to spot the last "Hint:" line. We can also render "Error:" and "Hint:" prefixes in different color/style.
This commit is contained in:
parent
b77a110e8a
commit
e50d96e01d
3 changed files with 27 additions and 23 deletions
|
@ -789,6 +789,9 @@ impl WorkspaceCommandHelper {
|
||||||
r#"Revset "{revision_str}" didn't resolve to any revisions"#
|
r#"Revset "{revision_str}" didn't resolve to any revisions"#
|
||||||
))),
|
))),
|
||||||
(Some(commit0), Some(commit1)) => {
|
(Some(commit0), Some(commit1)) => {
|
||||||
|
let mut cmd_err = user_error(format!(
|
||||||
|
r#"Revset "{revision_str}" resolved to more than one revision"#
|
||||||
|
));
|
||||||
let mut iter = [commit0, commit1].into_iter().chain(iter);
|
let mut iter = [commit0, commit1].into_iter().chain(iter);
|
||||||
let commits: Vec<_> = iter.by_ref().take(5).try_collect()?;
|
let commits: Vec<_> = iter.by_ref().take(5).try_collect()?;
|
||||||
let elided = iter.next().is_some();
|
let elided = iter.next().is_some();
|
||||||
|
@ -797,40 +800,41 @@ impl WorkspaceCommandHelper {
|
||||||
.map(|c| self.format_commit_summary(c))
|
.map(|c| self.format_commit_summary(c))
|
||||||
.join("\n")
|
.join("\n")
|
||||||
+ elided.then_some("\n...").unwrap_or_default();
|
+ elided.then_some("\n...").unwrap_or_default();
|
||||||
let hint = if commits[0].change_id() == commits[1].change_id() {
|
if commits[0].change_id() == commits[1].change_id() {
|
||||||
// Separate hint if there's commits with same change id
|
// Separate hint if there's commits with same change id
|
||||||
format!(
|
cmd_err.add_hint(format!(
|
||||||
r#"The revset "{revision_str}" resolved to these revisions:
|
r#"The revset "{revision_str}" resolved to these revisions:
|
||||||
{commits_summary}
|
{commits_summary}"#
|
||||||
Some of these commits have the same change id. Abandon one of them with `jj abandon -r <REVISION>`."#,
|
));
|
||||||
)
|
cmd_err.add_hint(
|
||||||
|
"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)) =
|
} else if let RevsetExpression::CommitRef(RevsetCommitRef::Symbol(branch_name)) =
|
||||||
revset_expression.as_ref()
|
revset_expression.as_ref()
|
||||||
{
|
{
|
||||||
// Separate hint if there's a conflicted branch
|
// Separate hint if there's a conflicted branch
|
||||||
format!(
|
cmd_err.add_hint(format!(
|
||||||
r#"Branch {branch_name} resolved to multiple revisions because it's conflicted.
|
r#"Branch {branch_name} resolved to multiple revisions because it's conflicted.
|
||||||
It resolved to these revisions:
|
It resolved to these revisions:
|
||||||
{commits_summary}
|
{commits_summary}"#));
|
||||||
Set which revision the branch points to with `jj branch set {branch_name} -r <REVISION>`."#,
|
cmd_err.add_hint(format!(
|
||||||
)
|
"Set which revision the branch points to with `jj branch set \
|
||||||
|
{branch_name} -r <REVISION>`.",
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
let mut hint = format!(
|
cmd_err.add_hint(format!(
|
||||||
r#"The revset "{revision_str}" resolved to these revisions:
|
r#"The revset "{revision_str}" resolved to these revisions:
|
||||||
{commits_summary}"#,
|
{commits_summary}"#,
|
||||||
);
|
));
|
||||||
if should_hint_about_all_prefix {
|
if should_hint_about_all_prefix {
|
||||||
hint.push_str(&format!(
|
cmd_err.add_hint(format!(
|
||||||
"\nPrefix the expression with 'all:' to allow any number of revisions \
|
"Prefix the expression with 'all:' to allow any number of revisions \
|
||||||
(i.e. 'all:{revision_str}')."
|
(i.e. 'all:{revision_str}')."
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
hint
|
|
||||||
};
|
};
|
||||||
Err(user_error_with_hint(
|
Err(cmd_err)
|
||||||
format!(r#"Revset "{revision_str}" resolved to more than one revision"#),
|
|
||||||
hint,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -497,7 +497,7 @@ fn test_new_conflicting_branches() {
|
||||||
It resolved to these revisions:
|
It resolved to these revisions:
|
||||||
kkmpptxz 66c6502d foo?? | (empty) two
|
kkmpptxz 66c6502d foo?? | (empty) two
|
||||||
qpvuntsm a9330854 foo?? | (empty) one
|
qpvuntsm a9330854 foo?? | (empty) one
|
||||||
Set which revision the branch points to with `jj branch set foo -r <REVISION>`.
|
Hint: Set which revision the branch points to with `jj branch set foo -r <REVISION>`.
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,7 +519,7 @@ fn test_new_conflicting_change_ids() {
|
||||||
Hint: The revset "qpvuntsm" resolved to these revisions:
|
Hint: The revset "qpvuntsm" resolved to these revisions:
|
||||||
qpvuntsm?? d2ae6806 (empty) two
|
qpvuntsm?? d2ae6806 (empty) two
|
||||||
qpvuntsm?? a9330854 (empty) one
|
qpvuntsm?? a9330854 (empty) one
|
||||||
Some of these commits have the same change id. Abandon one of them with `jj abandon -r <REVISION>`.
|
Hint: Some of these commits have the same change id. Abandon one of them with `jj abandon -r <REVISION>`.
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,7 @@ fn test_rebase_branch() {
|
||||||
Hint: The revset "e|d" resolved to these revisions:
|
Hint: The revset "e|d" resolved to these revisions:
|
||||||
znkkpsqq e52756c8 e | e
|
znkkpsqq e52756c8 e | e
|
||||||
vruxwmqv 514fa6b2 d | d
|
vruxwmqv 514fa6b2 d | d
|
||||||
Prefix the expression with 'all:' to allow any number of revisions (i.e. 'all:e|d').
|
Hint: Prefix the expression with 'all:' to allow any number of revisions (i.e. 'all:e|d').
|
||||||
"###);
|
"###);
|
||||||
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-b=all:e|d", "-d=b"]);
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-b=all:e|d", "-d=b"]);
|
||||||
insta::assert_snapshot!(stdout, @"");
|
insta::assert_snapshot!(stdout, @"");
|
||||||
|
@ -480,7 +480,7 @@ fn test_rebase_multiple_destinations() {
|
||||||
Hint: The revset "b|c" resolved to these revisions:
|
Hint: The revset "b|c" resolved to these revisions:
|
||||||
royxmykx fe2e8e8b c | c
|
royxmykx fe2e8e8b c | c
|
||||||
zsuskuln d370aee1 b | b
|
zsuskuln d370aee1 b | b
|
||||||
Prefix the expression with 'all:' to allow any number of revisions (i.e. 'all:b|c').
|
Hint: Prefix the expression with 'all:' to allow any number of revisions (i.e. 'all:b|c').
|
||||||
"###);
|
"###);
|
||||||
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-r", "a", "-d", "all:b|c"]);
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-r", "a", "-d", "all:b|c"]);
|
||||||
insta::assert_snapshot!(stdout, @"");
|
insta::assert_snapshot!(stdout, @"");
|
||||||
|
@ -616,7 +616,7 @@ fn test_rebase_with_descendants() {
|
||||||
Hint: The revset "b|d" resolved to these revisions:
|
Hint: The revset "b|d" resolved to these revisions:
|
||||||
vruxwmqv df54a9fd d | d
|
vruxwmqv df54a9fd d | d
|
||||||
zsuskuln d370aee1 b | b
|
zsuskuln d370aee1 b | b
|
||||||
Prefix the expression with 'all:' to allow any number of revisions (i.e. 'all:b|d').
|
Hint: Prefix the expression with 'all:' to allow any number of revisions (i.e. 'all:b|d').
|
||||||
"###);
|
"###);
|
||||||
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-s=all:b|d", "-d=a"]);
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-s=all:b|d", "-d=a"]);
|
||||||
insta::assert_snapshot!(stdout, @"");
|
insta::assert_snapshot!(stdout, @"");
|
||||||
|
|
Loading…
Reference in a new issue