diff --git a/src/commit.rs b/src/commit.rs index d7decb4..b7e0824 100644 --- a/src/commit.rs +++ b/src/commit.rs @@ -87,3 +87,15 @@ pub fn pre_commit_check(pre_commit_command: Option, message: &str) -> Re } Ok(()) } + +pub fn git_add_all_modified() -> Result<()> { + let output = git_exec(&["add", "-u"])?; + std::io::stdout().write_all(&output.stdout)?; + std::io::stderr().write_all(&output.stderr)?; + + if !output.status.success() { + return Err(anyhow!("Could not add files to staged area")); + } + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index fe33743..9134db8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,11 @@ clippy::cargo, clippy::str_to_string )] -#![allow(clippy::module_name_repetitions, clippy::multiple_crate_versions)] +#![allow( + clippy::module_name_repetitions, + clippy::multiple_crate_versions, + clippy::struct_excessive_bools +)] mod commit; mod commit_message; @@ -17,7 +21,8 @@ use std::io::Write; use std::path::PathBuf; use commit::{ - check_staged_files, commit, pre_commit_check, read_cached_commit, write_cached_commit, + check_staged_files, commit, git_add_all_modified, pre_commit_check, read_cached_commit, + write_cached_commit, }; use commit_message::make_message_commit; @@ -38,11 +43,18 @@ struct Args { /// Retry commit with the same message as the last one #[arg(short, long)] retry: bool, + /// Add all modified files into staging + #[arg(short, long)] + all: bool, } fn main() -> Result<()> { let args = Args::parse(); + if args.all { + git_add_all_modified()?; + } + check_staged_files()?; if args.init {