forked from mirrors/jj
cli: colorize commits summary embedded in single revset resolution hint
I think a colorized commit summary is easier to follow.
This commit is contained in:
parent
1061c91bde
commit
423a2a5446
2 changed files with 38 additions and 20 deletions
|
@ -795,27 +795,27 @@ impl WorkspaceCommandHelper {
|
||||||
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();
|
||||||
let commits_summary = {
|
let write_commits_summary = |formatter: &mut dyn Formatter| {
|
||||||
let template = self.commit_summary_template();
|
let template = self.commit_summary_template();
|
||||||
let mut output = Vec::new();
|
|
||||||
let mut formatter = PlainTextFormatter::new(&mut output);
|
|
||||||
for commit in &commits {
|
for commit in &commits {
|
||||||
write!(formatter, " ")?;
|
write!(formatter, " ")?;
|
||||||
template.format(commit, &mut formatter).unwrap();
|
template.format(commit, formatter)?;
|
||||||
writeln!(formatter).unwrap();
|
writeln!(formatter)?;
|
||||||
}
|
}
|
||||||
if elided {
|
if elided {
|
||||||
writeln!(formatter, " ...").unwrap();
|
writeln!(formatter, " ...")?;
|
||||||
}
|
}
|
||||||
output.pop(); // drop last newline
|
Ok(())
|
||||||
String::from_utf8(output).expect("template output should be utf-8 bytes")
|
|
||||||
};
|
};
|
||||||
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
|
||||||
cmd_err.add_hint(format!(
|
cmd_err.add_formatted_hint_with(|formatter| {
|
||||||
r#"The revset "{revision_str}" resolved to these revisions:
|
writeln!(
|
||||||
{commits_summary}"#
|
formatter,
|
||||||
));
|
r#"The revset "{revision_str}" resolved to these revisions:"#
|
||||||
|
)?;
|
||||||
|
write_commits_summary(formatter)
|
||||||
|
});
|
||||||
cmd_err.add_hint(
|
cmd_err.add_hint(
|
||||||
"Some of these commits have the same change id. Abandon one of them with \
|
"Some of these commits have the same change id. Abandon one of them with \
|
||||||
`jj abandon -r <REVISION>`.",
|
`jj abandon -r <REVISION>`.",
|
||||||
|
@ -824,19 +824,27 @@ impl WorkspaceCommandHelper {
|
||||||
revset_expression.as_ref()
|
revset_expression.as_ref()
|
||||||
{
|
{
|
||||||
// Separate hint if there's a conflicted branch
|
// Separate hint if there's a conflicted branch
|
||||||
cmd_err.add_hint(format!(
|
cmd_err.add_formatted_hint_with(|formatter| {
|
||||||
r#"Branch {branch_name} resolved to multiple revisions because it's conflicted.
|
writeln!(
|
||||||
It resolved to these revisions:
|
formatter,
|
||||||
{commits_summary}"#));
|
"Branch {branch_name} resolved to multiple revisions because it's \
|
||||||
|
conflicted."
|
||||||
|
)?;
|
||||||
|
writeln!(formatter, "It resolved to these revisions:")?;
|
||||||
|
write_commits_summary(formatter)
|
||||||
|
});
|
||||||
cmd_err.add_hint(format!(
|
cmd_err.add_hint(format!(
|
||||||
"Set which revision the branch points to with `jj branch set \
|
"Set which revision the branch points to with `jj branch set \
|
||||||
{branch_name} -r <REVISION>`.",
|
{branch_name} -r <REVISION>`.",
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
cmd_err.add_hint(format!(
|
cmd_err.add_formatted_hint_with(|formatter| {
|
||||||
r#"The revset "{revision_str}" resolved to these revisions:
|
writeln!(
|
||||||
{commits_summary}"#,
|
formatter,
|
||||||
));
|
r#"The revset "{revision_str}" resolved to these revisions:"#
|
||||||
|
)?;
|
||||||
|
write_commits_summary(formatter)
|
||||||
|
});
|
||||||
if should_hint_about_all_prefix {
|
if should_hint_about_all_prefix {
|
||||||
cmd_err.add_hint(format!(
|
cmd_err.add_hint(format!(
|
||||||
"Prefix the expression with 'all:' to allow any number of revisions \
|
"Prefix the expression with 'all:' to allow any number of revisions \
|
||||||
|
|
|
@ -429,6 +429,16 @@ fn test_color_ui_messages() {
|
||||||
[1m[39m<[38;5;1mError: [39mNo commit available>[0m [38;5;8m(elided revisions)[39m
|
[1m[39m<[38;5;1mError: [39mNo commit available>[0m [38;5;8m(elided revisions)[39m
|
||||||
[38;5;4m0000000000000000000000000000000000000000[39m
|
[38;5;4m0000000000000000000000000000000000000000[39m
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
|
// formatted hint
|
||||||
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["new", ".."]);
|
||||||
|
insta::assert_snapshot!(stderr, @r###"
|
||||||
|
[1m[38;5;1mError: [39mRevset ".." resolved to more than one revision[0m
|
||||||
|
[1m[38;5;6mHint: [0m[39mThe revset ".." resolved to these revisions:[39m
|
||||||
|
[39m [1m[38;5;5mm[0m[38;5;8mzvwutvl[39m [1m[38;5;4m1[0m[38;5;8m67f90e7[39m [38;5;2m(empty)[39m [38;5;2m(no description set)[39m[39m
|
||||||
|
[39m [1m[38;5;5mq[0m[38;5;8mpvuntsm[39m [1m[38;5;4m2[0m[38;5;8m30dd059[39m [38;5;2m(empty)[39m [38;5;2m(no description set)[39m[39m
|
||||||
|
[1m[38;5;6mHint: [0m[39mPrefix the expression with 'all:' to allow any number of revisions (i.e. 'all:..').[39m
|
||||||
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue