Skip to main content

git_same/workflows/
status_scan.rs

1//! Shared status scan workflow.
2
3use crate::config::{Config, WorkspaceConfig};
4use crate::discovery::DiscoveryOrchestrator;
5use crate::git::{GitOperations, ShellGit};
6use crate::tui::app::RepoEntry;
7
8/// Scan local repositories for git status for a workspace.
9#[cfg(feature = "tui")]
10pub fn scan_workspace_status(config: &Config, workspace: &WorkspaceConfig) -> Vec<RepoEntry> {
11    let base_path = workspace.expanded_base_path();
12    if !base_path.exists() {
13        return Vec::new();
14    }
15
16    let structure = workspace
17        .structure
18        .clone()
19        .unwrap_or_else(|| config.structure.clone());
20
21    let git = ShellGit::new();
22    let orchestrator = DiscoveryOrchestrator::new(workspace.filters.clone(), structure);
23    let local_repos = orchestrator.scan_local(&base_path, &git);
24
25    let mut entries = Vec::new();
26    for (path, org, name) in &local_repos {
27        let full_name = format!("{}/{}", org, name);
28        match git.status(path) {
29            Ok(s) => entries.push(RepoEntry {
30                owner: org.clone(),
31                name: name.clone(),
32                full_name,
33                path: path.clone(),
34                branch: if s.branch.is_empty() {
35                    None
36                } else {
37                    Some(s.branch)
38                },
39                is_uncommitted: s.is_uncommitted || s.has_untracked,
40                ahead: s.ahead as usize,
41                behind: s.behind as usize,
42                staged_count: s.staged_count,
43                unstaged_count: s.unstaged_count,
44                untracked_count: s.untracked_count,
45            }),
46            Err(_) => entries.push(RepoEntry {
47                owner: org.clone(),
48                name: name.clone(),
49                full_name,
50                path: path.clone(),
51                branch: None,
52                is_uncommitted: false,
53                ahead: 0,
54                behind: 0,
55                staged_count: 0,
56                unstaged_count: 0,
57                untracked_count: 0,
58            }),
59        }
60    }
61
62    entries
63}
64
65#[cfg(all(test, feature = "tui"))]
66#[path = "status_scan_tests.rs"]
67mod tests;