From 8eaaed240583242d3f66b92af1eb8eff2bf367b5 Mon Sep 17 00:00:00 2001 From: jianliang Date: Sat, 4 Nov 2023 02:14:39 -0400 Subject: [PATCH] Show head info of each sub-repository --- src/commands/status.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/commands/status.rs b/src/commands/status.rs index d6fa4a1..f840a4e 100644 --- a/src/commands/status.rs +++ b/src/commands/status.rs @@ -181,7 +181,13 @@ async fn show_status(root_dir: &PathBuf, mut output: impl std::io::Write) -> Res bifurcation, width = depth * TAB_SIZE )?; - writeln!(output, "{}", comp.name)?; + write!(output, "{}", comp.name)?; + + // Show head + let repo = Repository::open(&comp.target_dir)?; + let head = repo.head()?; + let head_info = head.shorthand().unwrap_or("unknown"); + writeln!(output, " ({})", head_info)?; // Directories of children should not be seen let mut children_names: Vec = vec![]; @@ -465,7 +471,7 @@ r#"deps = {{ println!("{}", output_str); let expected_output = " - (main) + (main) (main) Changes to be committed: new: test.txt @@ -475,8 +481,8 @@ r#"deps = {{ Changes untracked: test3.txt - ├─ sub2 - └─ sub2_sub1 + ├─ sub2 (main) + └─ sub2_sub1 (main) Changes to be committed: modified: test.txt @@ -487,15 +493,15 @@ r#"deps = {{ Changes untracked: test4.txt - └─ sub1 + └─ sub1 (main) Changes not staged: modified: test.txt Changes untracked: test2.txt - ├─ sub1_sub2 - └─ sub1_sub1 + ├─ sub1_sub2 (main) + └─ sub1_sub1 (main) Changes to be committed: deleted: test.txt