Module: ReactOnRails::GitUtils

Defined in:
lib/react_on_rails/git_utils.rb

Class Method Summary collapse

Class Method Details

.uncommitted_changes?(message_handler, git_installed: true) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/react_on_rails/git_utils.rb', line 7

def self.uncommitted_changes?(message_handler, git_installed: true)
  return false if ENV["COVERAGE"] == "true"

  status = `git status --porcelain`
  return false if git_installed && status&.empty?

  error = if git_installed
            <<~MSG.strip
              You have uncommitted changes. Please commit or stash them before continuing.

              The React on Rails generator creates many new files and it's important to keep
              your existing changes separate from the generated code for easier review.
            MSG
          else
            <<~MSG.strip
              Git is not installed. Please install Git and commit your changes before continuing.

              The React on Rails generator creates many new files and version control helps
              track what was generated versus your existing code.
            MSG
          end
  message_handler.add_error(error)
  true
end