Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -a flag to add all modified files into staging #45

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,10 @@ pub fn pre_commit_check(pre_commit_command: Option<String>, message: &str) -> Re
}
Ok(())
}

pub fn git_add_all_modified() -> Result<()> {
alt-art marked this conversation as resolved.
Show resolved Hide resolved
let output = git_exec(&["add", "-u"])?;
std::io::stdout().write_all(&output.stdout)?;
std::io::stderr().write_all(&output.stderr)?;
Ok(())
alt-art marked this conversation as resolved.
Show resolved Hide resolved
}
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
alt-art marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Parser, Debug)]
#[command(about, author, version)]
struct Args {
Expand All @@ -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 {
alt-art marked this conversation as resolved.
Show resolved Hide resolved
git_add_all_modified()?;
}

check_staged_files()?;

if args.init {
Expand Down
Loading