Module: ReactOnRails::GitUtils
- Defined in:
- lib/react_on_rails/git_utils.rb
Constant Summary collapse
- CI_TRUTHY_VALUES =
%w[1 true yes].freeze
- DIRTY_WORKTREE_WARNING =
<<~MSG.strip You have uncommitted changes. The generator will continue, but reviewing the generated diff is easier if you commit or stash your current work first. MSG
- MISSING_GIT_WARNING =
<<~MSG.strip Git is not installed. The generator will continue, but version control makes it much easier to review the generated changes and back out partial installs. MSG
- NOT_A_GIT_REPOSITORY_WARNING =
<<~MSG.strip Git is installed, but this directory is not a Git repository yet. The generator will continue, but initializing Git makes it much easier to review the generated changes and back out partial installs. MSG
Class Method Summary collapse
- .dirty_worktree_error_message ⇒ Object
- .missing_git_error_message ⇒ Object
- .not_a_git_repository_error_message ⇒ Object
- .skip_worktree_check? ⇒ Boolean
- .truthy_env?(value) ⇒ Boolean
- .uncommitted_changes?(message_handler, git_installed: true) ⇒ Boolean
- .warn_if_uncommitted_changes(message_handler, git_installed: true) ⇒ Object
- .worktree_status ⇒ Object
Class Method Details
.dirty_worktree_error_message ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/react_on_rails/git_utils.rb', line 78 def self. <<~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 end |
.missing_git_error_message ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/react_on_rails/git_utils.rb', line 87 def self. <<~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 |
.not_a_git_repository_error_message ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/react_on_rails/git_utils.rb', line 96 def self. <<~MSG.strip Git is installed, but this directory is not a Git repository yet. Initialize Git and commit or stash 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 |
.skip_worktree_check? ⇒ Boolean
34 35 36 |
# File 'lib/react_on_rails/git_utils.rb', line 34 def self.skip_worktree_check? truthy_env?(ENV.fetch("CI", nil)) || truthy_env?(ENV.fetch("COVERAGE", nil)) end |
.truthy_env?(value) ⇒ Boolean
38 39 40 |
# File 'lib/react_on_rails/git_utils.rb', line 38 def self.truthy_env?(value) CI_TRUTHY_VALUES.include?(value.to_s.strip.downcase) end |
.uncommitted_changes?(message_handler, git_installed: true) ⇒ Boolean
26 27 28 |
# File 'lib/react_on_rails/git_utils.rb', line 26 def self.uncommitted_changes?(, git_installed: true) report_worktree_issues(, git_installed: git_installed, as_error: true) end |
.warn_if_uncommitted_changes(message_handler, git_installed: true) ⇒ Object
30 31 32 |
# File 'lib/react_on_rails/git_utils.rb', line 30 def self.warn_if_uncommitted_changes(, git_installed: true) report_worktree_issues(, git_installed: git_installed, as_error: false) end |
.worktree_status ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/react_on_rails/git_utils.rb', line 42 def self.worktree_status output, status = Open3.capture2e("git", "status", "--porcelain") return :clean if status.success? && output.strip.empty? # Exit code 128 is git's standard fatal error (e.g., not a git repository) return :not_a_git_repository if status.exitstatus == 128 :dirty rescue Errno::ENOENT # git binary not found despite passing the cli_exists? check :git_not_installed end |