diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 9230f7bde..ff1d350c3 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -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(()) } diff --git a/tests/test_global_opts.rs b/tests/test_global_opts.rs index d9dbc7204..6eb7610c8 100644 --- a/tests/test_global_opts.rs +++ b/tests/test_global_opts.rs @@ -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. diff --git a/tests/test_status_command.rs b/tests/test_status_command.rs index 372abe848..1df92ad1f 100644 --- a/tests/test_status_command.rs +++ b/tests/test_status_command.rs @@ -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 "###); }