Skip to content

Commit ec09a63

Browse files
committed
Don't offer to do work if there are no changes at all
1 parent 3377234 commit ec09a63

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/main.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ When run with no arguments this will:
4242
",
4343
raw(max_term_width = "100"),
4444
raw(setting = "structopt::clap::AppSettings::UnifiedHelpMessage"),
45-
raw(setting = "structopt::clap::AppSettings::ColoredHelp"),
45+
raw(setting = "structopt::clap::AppSettings::ColoredHelp")
4646
)]
4747
struct Args {
4848
/// Use `squash!`: change the commit message that you amend
@@ -68,7 +68,7 @@ fn main() {
6868
// An empty message means don't display any error message
6969
let msg = e.to_string();
7070
if !msg.is_empty() {
71-
println!("Error running rebase: {}", e);
71+
println!("Error: {}", e);
7272
}
7373
}
7474
}
@@ -109,9 +109,14 @@ fn create_fixup_commit<'a>(
109109
) -> Result<Commit<'a>, Box<Error>> {
110110
let diffstat = diff.stats()?;
111111
if diffstat.files_changed() == 0 {
112-
print_diff(Changes::Unstaged)?;
113-
if !Confirmation::new("Nothing staged, stage and commit everything?").interact()? {
114-
return Err("".into());
112+
let dirty_workdir_stats = repo.diff_index_to_workdir(None, None)?.stats()?;
113+
if dirty_workdir_stats.files_changed() > 0 {
114+
print_diff(Changes::Unstaged)?;
115+
if !Confirmation::new("Nothing staged, stage and commit everything?").interact()? {
116+
return Err("".into());
117+
}
118+
} else {
119+
return Err("Nothing staged and no tracked files have any changes".into());
115120
}
116121
let pathspecs: Vec<&str> = vec![];
117122
let mut idx = repo.index()?;

0 commit comments

Comments
 (0)