Skip to main content

ai_agent/utils/git/
mod.rs

1// Source: /data/home/swei/claudecode/openclaudecode/src/utils/git.ts
2pub mod gitignore;
3
4use std::process::Command;
5
6pub fn git_exe() -> String {
7    "git".to_string()
8}
9
10pub fn get_remote_url() -> Option<String> {
11    let output = Command::new("git")
12        .args(["remote", "get-url", "origin"])
13        .output()
14        .ok()?;
15
16    if output.status.success() {
17        Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
18    } else {
19        None
20    }
21}
22
23pub fn is_git_repo() -> bool {
24    Command::new("git")
25        .args(["rev-parse", "--git-dir"])
26        .output()
27        .map(|o| o.status.success())
28        .unwrap_or(false)
29}
30
31pub fn get_current_branch() -> Option<String> {
32    let output = Command::new("git")
33        .args(["rev-parse", "--abbrev-ref", "HEAD"])
34        .output()
35        .ok()?;
36
37    if output.status.success() {
38        Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
39    } else {
40        None
41    }
42}