Skip to content

Commit 94a4b8e

Browse files
authored
Merge pull request #2 from JoshuaSBrown/JoshuaSBrown-avoid-commit-if-no-diff
Joshua s brown avoid commit if no diff
2 parents eb7cd20 + 9ebd755 commit 94a4b8e

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cpp-py-format"
3-
version = "0.2.3"
3+
version = "0.2.4"
44
authors = ["Andrew Gaspar <[email protected]>","Joshua Brown <[email protected]>"]
55
edition = "2018"
66

src/main.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -391,18 +391,26 @@ FLAGS:
391391
self.configure()?;
392392
self.format_all();
393393

394-
if !matches.is_present("amend") {
395-
assert!(cmd("git", &["commit", "-am", "cpp-py-formatter"])?
396-
.wait()?
397-
.success());
394+
let git_diff = Command::new("git")
395+
.args(&["diff", "--exit-code"])
396+
.output();
398397

399-
assert!(cmd("git", &["push"])?.wait()?.success());
400-
} else {
401-
assert!(cmd("git", &["commit", "-a", "--amend", "--no-edit"])?
402-
.wait()?
403-
.success());
398+
let git_diff_str = String::from_utf8_lossy(&git_diff.stdout);
399+
400+
if git_diff_str.len() > 0 {
401+
if !matches.is_present("amend") {
402+
assert!(cmd("git", &["commit", "-am", "cpp-py-formatter"])?
403+
.wait()?
404+
.success());
404405

405-
assert!(cmd("git", &["push", "--force"])?.wait()?.success());
406+
assert!(cmd("git", &["push"])?.wait()?.success());
407+
} else {
408+
assert!(cmd("git", &["commit", "-a", "--amend", "--no-edit"])?
409+
.wait()?
410+
.success());
411+
412+
assert!(cmd("git", &["push", "--force"])?.wait()?.success());
413+
}
406414
}
407415

408416
Ok(())

0 commit comments

Comments
 (0)