Skip to content

Commit 06f04f5

Browse files
authored
wait_for_newline=true in git add confirmation (#7)
1 parent c303e32 commit 06f04f5

File tree

4 files changed

+55
-18
lines changed

4 files changed

+55
-18
lines changed

Cargo.lock

Lines changed: 44 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2018"
88
anyhow = "1.0"
99
clap = { version = "2.33", features = ["wrap_help"] }
1010
console = "0.11"
11-
dialoguer = "0.6.0"
11+
dialoguer = "0.9.0"
1212
git2 = { version = "0.13.0", default_features = false }
1313
structopt = "0.3"
1414

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ pub fn instafix(
1717
max_commits: usize,
1818
message_pattern: Option<String>,
1919
upstream_branch_name: Option<&str>,
20+
require_newline: bool,
2021
) -> Result<(), anyhow::Error> {
2122
let repo = Repository::open(".")?;
22-
let diff = create_diff(&repo)?;
23+
let diff = create_diff(&repo, require_newline)?;
2324
let head = repo.head().context("finding head commit")?;
2425
let head_branch = Branch::wrap(head);
2526
let upstream = get_upstream(&repo, &head_branch, upstream_branch_name)?;
@@ -218,7 +219,7 @@ fn get_upstream<'a>(
218219
}
219220

220221
/// Get a diff either from the index or the diff from the index to the working tree
221-
fn create_diff(repo: &Repository) -> Result<Diff, anyhow::Error> {
222+
fn create_diff(repo: &Repository, require_newline: bool) -> Result<Diff, anyhow::Error> {
222223
let head = repo.head()?;
223224
let head_tree = head.peel_to_tree()?;
224225
let staged_diff = repo.diff_tree_to_index(Some(&head_tree), None, None)?;
@@ -230,6 +231,7 @@ fn create_diff(repo: &Repository) -> Result<Diff, anyhow::Error> {
230231
print_diff(Changes::Unstaged)?;
231232
if !Confirm::new()
232233
.with_prompt("Nothing staged, stage and commit everything?")
234+
.wait_for_newline(require_newline)
233235
.interact()?
234236
{
235237
bail!("");

src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use std::env;
1717
use structopt::StructOpt;
1818

1919
const UPSTREAM_VAR: &str = "GIT_INSTAFIX_UPSTREAM";
20+
const REQUIRE_NEWLINE: &str = "GIT_INSTAFIX_REQUIRE_NEWLINE";
2021

2122
#[derive(StructOpt, Debug)]
2223
#[structopt(
@@ -51,6 +52,10 @@ struct Args {
5152

5253
#[structopt(long, env(UPSTREAM_VAR))]
5354
default_upstream_branch: Option<String>,
55+
56+
/// Require a newline when confirming y/n questions
57+
#[structopt(long, env(REQUIRE_NEWLINE))]
58+
require_newline: bool,
5459
}
5560

5661
fn main() {
@@ -63,6 +68,7 @@ fn main() {
6368
args.max_commits,
6469
args.commit_message_pattern,
6570
args.default_upstream_branch.as_deref(),
71+
args.require_newline,
6672
) {
6773
// An empty message means don't display any error message
6874
let msg = e.to_string();

0 commit comments

Comments
 (0)