gitai/git/
utils.rs

1use anyhow::Result;
2use git2::Repository;
3
4/// Checks if the current directory is inside a Git work tree.
5///
6/// # Returns
7///
8/// A Result containing a boolean indicating if inside a work tree or an error.
9pub fn is_inside_work_tree() -> Result<bool> {
10    match Repository::discover(".") {
11        Ok(_) => Ok(true),
12        Err(_) => Ok(false),
13    }
14}
15
16/// Determines if the given diff represents a binary file.
17pub fn is_binary_diff(diff: &str) -> bool {
18    diff.contains("Binary files")
19        || diff.contains("GIT binary patch")
20        || diff.contains("[Binary file changed]")
21}