aqc_git_helpers/
queries.rs1use std::path::Path;
4
5use crate::error::GitError;
6use crate::git::worktree_changes;
7use crate::status::{PorcelainOptions, WorktreeChange};
8
9pub fn is_worktree_clean(
15 repo_root: impl AsRef<Path>,
16 options: PorcelainOptions,
17) -> Result<bool, GitError> {
18 Ok(worktree_changes(repo_root, options)?.is_empty())
19}
20
21#[must_use]
25pub fn changes_affecting_paths(changes: &[WorktreeChange], paths: &[&str]) -> Vec<WorktreeChange> {
26 let hits = |candidate: &str| {
27 paths
28 .iter()
29 .any(|p| candidate == *p || candidate.starts_with(&format!("{p}/")))
30 };
31 changes
32 .iter()
33 .filter(|c| hits(&c.path) || c.old_path.as_deref().is_some_and(hits))
34 .cloned()
35 .collect()
36}
37
38pub fn dirty_paths(
44 repo_root: impl AsRef<Path>,
45 paths: &[&str],
46 options: PorcelainOptions,
47) -> Result<Vec<WorktreeChange>, GitError> {
48 let changes = worktree_changes(repo_root, options)?;
49 Ok(changes_affecting_paths(&changes, paths))
50}