Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update #uncommitted_changes? to handle missing Git #889

Merged
merged 2 commits into from
Jul 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.5]
### 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 @@ -23,9 +25,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 @@ -49,7 +51,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
10 changes: 8 additions & 2 deletions lib/react_on_rails/git_utils.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# frozen_string_literal: true

require "English"

module ReactOnRails
module GitUtils
def self.uncommitted_changes?(message_handler)
return false if ENV["COVERAGE"] == "true"
status = `git status --porcelain`
return false if status.empty?
error = "You have uncommitted code. Please commit or stash your changes before continuing"
return false if $CHILD_STATUS.success? && status.empty?
error = if !$CHILD_STATUS.success?
"You do not have Git installed. Please install Git, and commit your changes before continuing"
else
"You have uncommitted code. Please commit or stash your changes before continuing"
end
message_handler.add_error(error)
true
end
Expand Down
56 changes: 56 additions & 0 deletions spec/react_on_rails/git_utils_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 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)
allow_any_instance_of(Process::Status).to receive(:success?).and_return(true)
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)
allow_any_instance_of(Process::Status).to receive(:success?).and_return(true)
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 not installed" do
subject { nil }
let(:message_handler) { instance_double("MessageHandler") }

before do
allow(described_class).to receive(:`).with("git status --porcelain").and_return(subject)
allow_any_instance_of(Process::Status).to receive(:success?).and_return(false)
expect(message_handler).to receive(:add_error)
.with("You do not have Git installed. Please install Git, and commit your changes before continuing")
end

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