git_x/
undo.rs

1use crate::command::Command;
2use crate::core::git::GitOperations;
3use crate::core::output::Format;
4
5pub fn run() -> crate::Result<()> {
6    let cmd = UndoCommand;
7    cmd.execute(())
8}
9
10/// Command implementation for git undo
11pub struct UndoCommand;
12
13impl Command for UndoCommand {
14    type Input = ();
15    type Output = ();
16
17    fn execute(&self, _input: ()) -> crate::Result<()> {
18        GitOperations::run_status(&["reset", "--soft", "HEAD~1"])?;
19        println!(
20            "{}",
21            Format::success("Last commit undone (soft reset). Changes kept in working directory.")
22        );
23        Ok(())
24    }
25
26    fn name(&self) -> &'static str {
27        "undo"
28    }
29
30    fn description(&self) -> &'static str {
31        "Undo the last commit (without losing changes)"
32    }
33
34    fn is_destructive(&self) -> bool {
35        true
36    }
37}