use crate::error::Result;
use colored::*;
use std::path::Path;
use std::process::Command;
pub fn init_repository(project_path: &Path) -> Result<()> {
let status = Command::new("git")
.arg("init")
.current_dir(project_path)
.status()?;
if !status.success() {
return Err(anyhow::anyhow!("Failed to initialize git repository"));
}
println!("{}", "✓ Initialized git repository".green());
Ok(())
}
pub fn add_remote(project_path: &Path, remote_url: &str) -> Result<()> {
let status = Command::new("git")
.args(["remote", "add", "origin", remote_url])
.current_dir(project_path)
.status()?;
if !status.success() {
return Err(anyhow::anyhow!("Failed to add git remote"));
}
Ok(())
}
pub fn initial_commit(project_path: &Path) -> Result<()> {
Command::new("git")
.args(["add", "."])
.current_dir(project_path)
.status()?;
let status = Command::new("git")
.args(["commit", "-m", "Initial commit"])
.current_dir(project_path)
.status()?;
if !status.success() {
return Err(anyhow::anyhow!("Failed to create initial commit"));
}
println!("{}", "✓ Created initial commit".green());
Ok(())
}
pub fn push_to_remote(project_path: &Path) -> Result<()> {
let status = Command::new("git")
.args(["push", "-u", "origin", "main"])
.current_dir(project_path)
.status()?;
if !status.success() {
return Err(anyhow::anyhow!("Failed to push to remote"));
}
println!("{}", "✓ Pushed to remote repository".green());
Ok(())
}
pub fn configure_hooks(project_path: &Path) -> Result<()> {
let status = Command::new("git")
.args(["config", "core.hooksPath", ".githooks"])
.current_dir(project_path)
.status()?;
if status.success() {
println!("{}", "✓ Configured git hooks".green());
}
Ok(())
}