Skip to content

Commit 3d528e7

Browse files
committed
feat: stage changes with -am flag
Signed-off-by: Matt Gleich <git@mattglei.ch>
1 parent c2a4287 commit 3d528e7

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use clap::{Arg, Command};
22

33
pub fn setup() -> Command {
44
Command::new("resin")
5-
.version("1.6.3")
5+
.version("1.6.4")
66
.author("Matt Gleich <email@mattglei.ch>")
77
.about("Fast CLI for conventional commits\nhttps://github.com/gleich/resin")
88
.arg(
99
Arg::new("all")
10-
.help("Stage all changes in the current directory before committing")
10+
.help("Commit all of the unstaged changes too")
1111
.short('a')
1212
.long("all")
1313
.num_args(0),

src/git.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fs;
2-
use std::process::{exit, Command, ExitStatus};
2+
use std::process::{Command, ExitStatus, exit};
33

4-
use anyhow::{anyhow, bail, Context, Result};
4+
use anyhow::{Context, Result, anyhow, bail};
55
use clap::ArgMatches;
66
use configparser::ini::Ini;
77
use directories::UserDirs;
@@ -13,21 +13,22 @@ use crate::utils::{output_failure, output_success};
1313
pub fn commit_changes(conf: &Config, args: &ArgMatches, inputs: &Inputs) -> Result<()> {
1414
let git_program = "git";
1515
println!();
16-
if args.get_flag("all") {
17-
let status = Command::new(git_program)
18-
.args(["add", "--verbose", "."])
19-
.status()
20-
.context("Failed to stage all changes")?;
21-
check_status(status, "stage all changes");
22-
output_success("Staged all changes\n");
23-
}
2416

17+
let all_flag = args.get_flag("all");
2518
let status = Command::new(git_program)
26-
.args(["commit", "-m", &message(conf, inputs)?])
19+
.args([
20+
"commit",
21+
if all_flag { "-am" } else { "-m" },
22+
&message(conf, inputs)?,
23+
])
2724
.status()
2825
.context("Failed to commit changes")?;
2926
check_status(status, "commit changes");
30-
output_success("Committed changes");
27+
output_success(if all_flag {
28+
"Committed all changes"
29+
} else {
30+
"Committed changes"
31+
});
3132

3233
if args.get_flag("push") {
3334
println!();

0 commit comments

Comments
 (0)