Skip to content

Commit

Permalink
feat(commit)!: add flags for intent_to_add and patch
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The defaults of these flags disable the previous behavior of automatically calling git add -N and git add -p

Refs: #151
  • Loading branch information
hdevalke committed Oct 13, 2023
1 parent 76fb072 commit 252c136
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,18 @@ pub struct CommitCommand {
/// Introduces a breaking change
#[clap(long)]
pub breaking: bool,
/// Interactive mode
/// Interactive mode. Start the wizard if no type and description is given.
#[clap(long, short, env = "CONVCO_INTERACTIVE")]
pub interactive: bool,
/// Runs `git add -N <PATH>`.
/// An entry for the path is placed in the index with no content.
/// This is useful in combination with --patch.
#[clap(short = 'N', long, env = "CONVCO_INTENT_TO_ADD")]
pub intent_to_add: Vec<PathBuf>,
/// Runs `git add -p`.
/// Interactively choose hunks of patch between the index and the work tree.
#[clap(short, long, env = "CONVCO_PATCH")]
pub patch: bool,
/// Extra arguments passed to the git commit command
#[clap(last = true)]
pub extra_args: Vec<String>,
Expand Down
17 changes: 12 additions & 5 deletions src/cmd/commit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::process::{self, ExitStatus};
use std::{
path::PathBuf,
process::{self, ExitStatus},
};

use handlebars::{no_escape, Handlebars};
use regex::Regex;
Expand Down Expand Up @@ -35,9 +38,9 @@ impl CommitCommand {
Ok(cmd.status()?)
}

fn intend_to_add(&self) -> Result<ExitStatus, Error> {
fn intend_to_add(&self, paths: &[PathBuf]) -> Result<ExitStatus, Error> {
let mut cmd = process::Command::new("git");
Ok(cmd.args(["add", "-N", "."]).status()?)
Ok(cmd.args(["add", "-N"]).args(paths).status()?)
}

fn patch(&self) -> Result<ExitStatus, Error> {
Expand Down Expand Up @@ -210,8 +213,12 @@ impl Dialog {

impl Command for CommitCommand {
fn exec(&self, config: Config) -> anyhow::Result<()> {
self.intend_to_add()?;
self.patch()?;
if !self.intent_to_add.is_empty() {
self.intend_to_add(self.intent_to_add.as_slice())?;
}
if self.patch {
self.patch()?;
}
let r#type = match (
self.feat,
self.fix,
Expand Down

0 comments on commit 252c136

Please sign in to comment.