cli: color branch name and conflict marker in jj branches output

This commit is contained in:
Martin von Zweigbergk 2021-08-11 08:46:57 -07:00
parent 4594932fc0
commit 4878c94052
2 changed files with 11 additions and 3 deletions

View file

@ -2114,16 +2114,23 @@ fn cmd_branches(
let repo_command = command.repo_helper(ui)?;
let repo = repo_command.repo();
for (name, branch_target) in repo.view().branches() {
ui.stdout_formatter().add_label("branch".to_string())?;
write!(ui, "{}", name)?;
ui.stdout_formatter().remove_label()?;
if let Some(local_target) = &branch_target.local_target {
match local_target {
RefTarget::Normal(id) => {
write!(ui, "{}: ", name)?;
write!(ui, ": ")?;
let commit = repo.store().get_commit(id)?;
ui.write_commit_summary(repo.as_repo_ref(), &commit)?;
writeln!(ui)?;
}
RefTarget::Conflict { adds, removes } => {
writeln!(ui, "{} (conflicted):", name)?;
write!(ui, " ")?;
ui.stdout_formatter().add_label("conflict".to_string())?;
write!(ui, "(conflicted)")?;
ui.stdout_formatter().remove_label()?;
writeln!(ui, ":")?;
for id in removes {
let commit = repo.store().get_commit(id)?;
write!(ui, " - ")?;
@ -2139,7 +2146,7 @@ fn cmd_branches(
}
}
} else {
writeln!(ui, "{} (deleted)", name)?;
writeln!(ui, " (deleted)")?;
}
// TODO: Display information about remote branches, but probably only

View file

@ -88,6 +88,7 @@ fn config_colors(user_settings: &UserSettings) -> HashMap<String, String> {
result.insert(String::from("author timestamp"), String::from("cyan"));
result.insert(String::from("committer"), String::from("yellow"));
result.insert(String::from("committer timestamp"), String::from("cyan"));
result.insert(String::from("branch"), String::from("magenta"));
result.insert(String::from("branches"), String::from("magenta"));
result.insert(String::from("tags"), String::from("magenta"));
result.insert(String::from("git_refs"), String::from("magenta"));