use anyhow::Result;
use clap::Args;
use crate::output;
#[derive(Args)]
pub struct ModifyArgs {
#[arg(short, long)]
message: Option<String>,
#[arg(long)]
no_edit: bool,
#[arg(long)]
commit: bool,
}
pub async fn execute(args: ModifyArgs) -> Result<()> {
let mut cmd = std::process::Command::new("git");
if args.commit {
cmd.arg("commit");
if let Some(msg) = &args.message {
cmd.args(["-m", msg]);
}
} else {
cmd.args(["commit", "--amend"]);
if args.no_edit {
cmd.arg("--no-edit");
} else if let Some(msg) = &args.message {
cmd.args(["-m", msg]);
}
}
let status = cmd.status()?;
if status.success() {
if args.commit {
output::success("Created new commit");
} else {
output::success("Amended commit");
}
output::hint("Run 'gt restack' to update dependent branches");
}
Ok(())
}