From 31a0e4c4ba9d01e0bf40ce563cc1d616f15fc260 Mon Sep 17 00:00:00 2001 From: terade <134976752+terade@users.noreply.github.com.> Date: Tue, 10 Oct 2023 19:17:00 +0200 Subject: [PATCH 1/4] feat(main.rs, commit.rs): Add -a flag to add all modified files into staging. Add -a (--all) flag to add all modified files into staging. Same result as executing git add -u beforehand. closes issue #44 --- src/commit.rs | 7 +++++++ src/main.rs | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/commit.rs b/src/commit.rs index d7decb4..fe2f636 100644 --- a/src/commit.rs +++ b/src/commit.rs @@ -87,3 +87,10 @@ 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)?; + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index fe33743..83d9cd9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,12 +17,14 @@ 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; const DEFAULT_CONFIG_FILE: &str = include_str!("../commit-default.json"); +#[allow(clippy::pedantic)] #[derive(Parser, Debug)] #[command(about, author, version)] struct Args { @@ -38,11 +40,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 { From 7e780cab7b7de29563de436ca355da0ea847f6d5 Mon Sep 17 00:00:00 2001 From: terade <134976752+terade@users.noreply.github.com.> Date: Tue, 10 Oct 2023 20:32:01 +0200 Subject: [PATCH 2/4] fix(main.rs): Modify clippy lints Modify clippy lints to be more specific. #44 --- src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 83d9cd9..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; @@ -24,7 +28,6 @@ use commit_message::make_message_commit; const DEFAULT_CONFIG_FILE: &str = include_str!("../commit-default.json"); -#[allow(clippy::pedantic)] #[derive(Parser, Debug)] #[command(about, author, version)] struct Args { From cb81ba380a2e0713fc05b5f31ba8cdb867d942e6 Mon Sep 17 00:00:00 2001 From: terade <134976752+terade@users.noreply.github.com.> Date: Tue, 10 Oct 2023 20:56:39 +0200 Subject: [PATCH 3/4] fix(commit.rs): Fix missing error handling in git_add_all_modified() addressing issue #44 --- src/commit.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/commit.rs b/src/commit.rs index fe2f636..782900f 100644 --- a/src/commit.rs +++ b/src/commit.rs @@ -92,5 +92,12 @@ 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!( + "Failed to get git path. Make sure you are in a git repository" + )); + } + Ok(()) } From 4e6e83bd371ed3e8bd717b108ee730c9dbb32b2a Mon Sep 17 00:00:00 2001 From: terade <134976752+terade@users.noreply.github.com.> Date: Tue, 10 Oct 2023 21:03:46 +0200 Subject: [PATCH 4/4] fix(commit.rs): Change error message for git_add_all_modified #44 --- src/commit.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/commit.rs b/src/commit.rs index 782900f..b7e0824 100644 --- a/src/commit.rs +++ b/src/commit.rs @@ -94,9 +94,7 @@ pub fn git_add_all_modified() -> Result<()> { std::io::stderr().write_all(&output.stderr)?; if !output.status.success() { - return Err(anyhow!( - "Failed to get git path. Make sure you are in a git repository" - )); + return Err(anyhow!("Could not add files to staged area")); } Ok(())