mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 22:49:42 +00:00
29 lines
647 B
Rust
29 lines
647 B
Rust
use std::path::Path;
|
|
use std::process::Command;
|
|
|
|
pub fn is_git_available() -> bool {
|
|
Command::new("git")
|
|
.arg("--version")
|
|
.output()
|
|
.map(|o| o.status.success())
|
|
.unwrap_or(false)
|
|
}
|
|
|
|
pub fn git_init(path: &Path) -> Result<(), String> {
|
|
if !is_git_available() {
|
|
return Err("git executable not found in PATH".to_string());
|
|
}
|
|
|
|
let status = Command::new("git")
|
|
.arg("init")
|
|
.current_dir(path)
|
|
.status()
|
|
.map_err(|e| format!("failed to execute git init: {}", e))?;
|
|
|
|
if !status.success() {
|
|
return Err("git init failed".to_string());
|
|
}
|
|
|
|
Ok(())
|
|
}
|