From 41e4c062f6edcc439087fa00b5c044e71adac712 Mon Sep 17 00:00:00 2001 From: Jason Blalock Date: Mon, 17 Jul 2017 03:30:17 -0400 Subject: [PATCH] Update #uncommitted_changes? to handle missing Git (#889) * Update #uncommitted_changes? to handle missing Git - 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 #888 * Add explicit message when Git is not installed --- CHANGELOG.md | 8 ++-- lib/react_on_rails/git_utils.rb | 10 ++++- spec/react_on_rails/git_utils_spec.rb | 56 +++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 spec/react_on_rails/git_utils_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index af94cf567..d42288da2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,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). @@ -27,9 +29,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 @@ -53,7 +55,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 diff --git a/lib/react_on_rails/git_utils.rb b/lib/react_on_rails/git_utils.rb index 236bd4ff3..c0a9c59c5 100644 --- a/lib/react_on_rails/git_utils.rb +++ b/lib/react_on_rails/git_utils.rb @@ -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 diff --git a/spec/react_on_rails/git_utils_spec.rb b/spec/react_on_rails/git_utils_spec.rb new file mode 100644 index 000000000..f9e2bd989 --- /dev/null +++ b/spec/react_on_rails/git_utils_spec.rb @@ -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