cli status: rearrange sections

Puts the commit summary the working copy before the info about parent
commits, to match the output after most mutating commands.

Also puts the working copy diff before the commit summary, to keep it next to
the info about the working copy commit.
This commit is contained in:
Ilya Grigoriev 2023-07-10 21:22:43 -07:00
parent d591b6776d
commit 44903ed603
3 changed files with 32 additions and 33 deletions

View file

@ -1492,15 +1492,38 @@ fn cmd_status(
ui.request_pager();
let mut formatter = ui.stdout_formatter();
let formatter = formatter.as_mut();
if let Some(wc_commit) = &maybe_wc_commit {
let parent_tree = merge_commit_trees(repo.as_ref(), &wc_commit.parents())?;
let tree = wc_commit.tree();
if tree.id() == parent_tree.id() {
formatter.write_str("The working copy is clean\n")?;
} else {
formatter.write_str("Working copy changes:\n")?;
diff_util::show_diff_summary(
formatter,
&workspace_command,
parent_tree.diff(&tree, &EverythingMatcher),
)?;
}
let conflicts = wc_commit.merged_tree()?.conflicts().collect_vec();
if !conflicts.is_empty() {
writeln!(
formatter.labeled("conflict"),
"There are unresolved conflicts at these paths:"
)?;
print_conflicted_paths(&conflicts, formatter, &workspace_command)?
}
formatter.write_str("Working copy : ")?;
workspace_command.write_commit_summary(formatter, wc_commit)?;
formatter.write_str("\n")?;
for parent in wc_commit.parents() {
formatter.write_str("Parent commit: ")?;
workspace_command.write_commit_summary(formatter, &parent)?;
formatter.write_str("\n")?;
}
formatter.write_str("Working copy : ")?;
workspace_command.write_commit_summary(formatter, wc_commit)?;
formatter.write_str("\n")?;
} else {
formatter.write_str("No working copy\n")?;
}
@ -1549,30 +1572,6 @@ fn cmd_status(
)?;
}
if let Some(wc_commit) = &maybe_wc_commit {
let parent_tree = merge_commit_trees(repo.as_ref(), &wc_commit.parents())?;
let tree = wc_commit.tree();
if tree.id() == parent_tree.id() {
formatter.write_str("The working copy is clean\n")?;
} else {
formatter.write_str("Working copy changes:\n")?;
diff_util::show_diff_summary(
formatter,
&workspace_command,
parent_tree.diff(&tree, &EverythingMatcher),
)?;
}
let conflicts = wc_commit.merged_tree()?.conflicts().collect_vec();
if !conflicts.is_empty() {
writeln!(
formatter.labeled("conflict"),
"There are unresolved conflicts at these paths:"
)?;
print_conflicted_paths(&conflicts, formatter, &workspace_command)?
}
}
Ok(())
}

View file

@ -157,9 +157,9 @@ fn test_resolve_workspace_directory() {
// Ancestor of cwd
let stdout = test_env.jj_cmd_success(&subdir, &["status"]);
insta::assert_snapshot!(stdout, @r###"
Parent commit: zzzzzzzz 00000000 (empty) (no description set)
Working copy : qpvuntsm 230dd059 (empty) (no description set)
The working copy is clean
Working copy : qpvuntsm 230dd059 (empty) (no description set)
Parent commit: zzzzzzzz 00000000 (empty) (no description set)
"###);
// Explicit subdirectory path
@ -171,9 +171,9 @@ fn test_resolve_workspace_directory() {
// Valid explicit path
let stdout = test_env.jj_cmd_success(&subdir, &["status", "-R", "../.."]);
insta::assert_snapshot!(stdout, @r###"
Parent commit: zzzzzzzz 00000000 (empty) (no description set)
Working copy : qpvuntsm 230dd059 (empty) (no description set)
The working copy is clean
Working copy : qpvuntsm 230dd059 (empty) (no description set)
Parent commit: zzzzzzzz 00000000 (empty) (no description set)
"###);
// "../../..".ancestors() contains "../..", but it should never be looked up.

View file

@ -33,9 +33,9 @@ fn test_status_merge() {
// to the auto-merged parents)
let stdout = test_env.jj_cmd_success(&repo_path, &["status"]);
insta::assert_snapshot!(stdout, @r###"
The working copy is clean
Working copy : mzvwutvl c965365c (empty) (no description set)
Parent commit: rlvkpnrz 9ae48ddb (empty) left
Parent commit: zsuskuln 29b991e9 right
Working copy : mzvwutvl c965365c (empty) (no description set)
The working copy is clean
"###);
}