use std::path::Path;
use anyhow::Result;
use crate::output::{ResetMode, ResetOutput};
use crate::{GitModule, TIMEOUT_LOCAL, git_cmd};
impl GitModule {
pub async fn reset(
&self,
working_dir: &Path,
mode: ResetMode,
target: &str,
) -> Result<ResetOutput> {
self.ensure_session_scope(working_dir)?;
let previous_head = git_cmd(working_dir, &["rev-parse", "HEAD"], TIMEOUT_LOCAL).await?;
let flag = match mode {
ResetMode::Soft => "--soft",
ResetMode::Mixed => "--mixed",
ResetMode::Hard => "--hard",
};
git_cmd(working_dir, &["reset", flag, target], TIMEOUT_LOCAL).await?;
let current_head = git_cmd(working_dir, &["rev-parse", "HEAD"], TIMEOUT_LOCAL).await?;
Ok(ResetOutput {
mode,
target: target.to_string(),
previous_head,
current_head,
})
}
}