Skip to content

Commit a48574d

Browse files
authored
Merge pull request #6 from github/rescue_empty_commit
Rescue CommandError so we don't push empty commits, but don't fail ei…
2 parents 7093757 + 7acb42c commit a48574d

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
entitlements-gitrepo-auditor-plugin (0.2.0)
4+
entitlements-gitrepo-auditor-plugin (0.2.1)
55
contracts (= 0.17)
66
entitlements (= 0.2.0)
77

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.0
1+
0.2.1

lib/entitlements/util/gitrepo.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ def clone(dir)
7979
Contract String, String => nil
8080
def commit(dir, commit_message)
8181
validate_git_repository!(dir)
82-
git(dir, ["commit", "-m", commit_message])
82+
begin
83+
git(dir, ["commit", "-m", commit_message])
84+
rescue Entitlements::Util::GitRepo::CommandError
85+
logger.info "No changes to git repository"
86+
end
8387
nil
8488
end
8589

spec/unit/entitlements/util/gitrepo_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
expect(subject).to receive(:git).with(directory, ["commit", "-m", "My commit message"])
4040
expect(subject.commit(directory, "My commit message")).to be nil
4141
end
42+
43+
it "skips the commit if it receives a command error" do
44+
allow(subject).to receive(:validate_git_repository!)
45+
expect(subject).to receive(:git).with(directory, ["commit", "-m", "My commit message"]).and_raise(Entitlements::Util::GitRepo::CommandError)
46+
expect(logger).to receive(:info).with("No changes to git repository")
47+
expect(subject.commit(directory, "My commit message")).to be nil
48+
end
4249
end
4350

4451
describe "#configure" do

0 commit comments

Comments
 (0)