use std::path::Path;
use anyhow::Result;
pub fn commit_amend(workdir: &Path, message: Option<&str>) -> Result<()> {
if let Some(msg) = message {
super::run_git(
workdir,
&["commit", "--allow-empty", "--amend", "--only", "-m", msg],
)
} else {
super::run_git_interactive(workdir, &["commit", "--allow-empty", "--amend", "--only"])
}
}
pub fn commit_amend_no_edit(workdir: &Path) -> Result<()> {
super::run_git(
workdir,
&["commit", "--amend", "--no-edit", "--allow-empty"],
)
}
pub fn stage_files(workdir: &Path, files: &[&str]) -> Result<()> {
let mut args = vec!["add", "--"];
args.extend(files);
super::run_git(workdir, &args)
}
pub fn stage_path(workdir: &Path, path: &str) -> Result<()> {
if super::run_git(workdir, &["add", "--", path]).is_ok() {
return Ok(());
}
super::run_git(workdir, &["rm", "-f", "--", path])
}
pub fn commit(workdir: &Path, message: &str) -> Result<()> {
super::run_git(workdir, &["commit", "-m", message])
}
pub fn reset_mixed(workdir: &Path, target: &str) -> Result<()> {
super::run_git(workdir, &["reset", target])
}
pub fn reset_hard(workdir: &Path, target: &str) -> Result<()> {
super::run_git(workdir, &["reset", "--hard", target])
}
pub fn stage_all(workdir: &Path) -> Result<()> {
super::run_git(workdir, &["add", "-A"])
}
pub fn commit_with_editor(workdir: &Path) -> Result<()> {
super::run_git_interactive(workdir, &["commit"])
}