kimun_notes/util/git_status.rs
1//! Workspace git-status summary for the status bar (display only — spec §12
2//! keeps every other git interaction out of scope).
3//!
4//! This shells out to the user's `git`; it is repo metadata, not a vault
5//! file operation, so it lives in the TUI rather than core.
6
7use std::path::PathBuf;
8
9/// Status-bar segment for the workspace's git state:
10/// - `Some("git ✓")` — clean working tree
11/// - `Some("git ●N")` — N changed paths
12/// - `None` — `git` missing or the workspace is not a repository
13pub async fn fetch(root: PathBuf) -> Option<String> {
14 let out = tokio::process::Command::new("git")
15 .arg("-C")
16 .arg(&root)
17 .args(["status", "--porcelain"])
18 .output()
19 .await
20 .ok()?;
21 if !out.status.success() {
22 return None;
23 }
24 let dirty = String::from_utf8_lossy(&out.stdout)
25 .lines()
26 .filter(|l| !l.trim().is_empty())
27 .count();
28 Some(if dirty == 0 {
29 "git ✓".to_string()
30 } else {
31 format!("git ●{dirty}")
32 })
33}