Skip to content

Commit

Permalink
Update #uncommitted_changes? to handle missing Git
Browse files Browse the repository at this point in the history
- Fix for GitUtils.uncommitted_changes? throwing an error when called in
  an environment that does not have git installed
- Add tests for GitUtils.uncommitted_changes? scenariors
- Fixes shakacode#888
  • Loading branch information
jasonblalock committed Jul 5, 2017
1 parent 51a4630 commit 62f6975
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Changes since last non-beta release.

*Please add entries here for your pull requests.*

- Fixes GitUtils.uncommitted_changes? throwing an error when called in an environment without Git, and allows install generator to be run successfully with `--ignore-warnings` [#878](https://github.com/shakacode/react_on_rails/pull/878) by [jasonblalock](https://github.com/jasonblalock)

## [8.0.4]
### Fixed
- Corrects `devBuild` value for webpack production build from webpackConfigLoader. [#877](https://github.com/shakacode/react_on_rails/pull/877) by [chenqingspring](https://github.com/chenqingspring).
Expand All @@ -19,9 +21,9 @@ Changes since last non-beta release.

## [8.0.2]
### Fixed
- Any failure in webpack to build test files quits tests.
- Any failure in webpack to build test files quits tests.
- Fixed a Ruby 2.4 potential crash which could cause a crash due to pathname change in Ruby 2.4.
- CI Improvements:
- CI Improvements:
- Switched to yarn link and removed relative path install of react-on-rails
- Removed testing of Turbolinks 2
- All tests run against Rails 5.1.1
Expand All @@ -45,7 +47,7 @@ Changes since last non-beta release.
### Changed
- Major updates for WebpackerLite 2.0.2. [#844](https://github.com/shakacode/react_on_rails/pull/845) by [justin808](https://github.com/justin808) with help from ](https://github.com/robwise)
- Logging no longer occurs when trace is turned to false. [#845](https://github.com/shakacode/react_on_rails/pull/845) by [conturbo](https://github.com/Conturbo)

## [8.0.0-beta.2] - 2017-05-08

### Changed
Expand Down
2 changes: 1 addition & 1 deletion lib/react_on_rails/git_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module GitUtils
def self.uncommitted_changes?(message_handler)
return false if ENV["COVERAGE"] == "true"
status = `git status --porcelain`
return false if status.empty?
return false if !status.nil? && status.empty?
error = "You have uncommitted code. Please commit or stash your changes before continuing"
message_handler.add_error(error)
true
Expand Down
53 changes: 53 additions & 0 deletions spec/react_on_rails/git_utils_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# frozen_string_literal: true

require_relative "spec_helper"

module ReactOnRails
RSpec.describe GitUtils do
describe ".uncommitted_changes?" do
context "With uncommited git changes" do
subject { "M file/path" }
let(:message_handler) { instance_double("MessageHandler") }

before do
allow(described_class).to receive(:`).with("git status --porcelain").and_return(subject)
expect(message_handler).to receive(:add_error)
.with("You have uncommitted code. Please commit or stash your changes before continuing")
end

it "returns true" do
expect(described_class.uncommitted_changes?(message_handler)).to eq(true)
end
end

context "With clean git status" do
subject { "" }
let(:message_handler) { instance_double("MessageHandler") }

before do
allow(described_class).to receive(:`).with("git status --porcelain").and_return(subject)
expect(message_handler).not_to receive(:add_error)
end

it "returns false" do
expect(described_class.uncommitted_changes?(message_handler)).to eq(false)
end
end

context "With git status failure" do
subject { nil }
let(:message_handler) { instance_double("MessageHandler") }

before do
allow(described_class).to receive(:`).with("git status --porcelain").and_return(subject)
expect(message_handler).to receive(:add_error)
.with("You have uncommitted code. Please commit or stash your changes before continuing")
end

it "returns true" do
expect(described_class.uncommitted_changes?(message_handler)).to eq(true)
end
end
end
end
end

0 comments on commit 62f6975

Please sign in to comment.