class RubyCritic::SourceControlSystem::Git

Constants

GIT_EXECUTABLE
Stats

Public Class Methods

current_branch() click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 82
def self.current_branch
  branch_list = `git branch`
  branch = branch_list.match(/\*.*$/)[0].gsub('* ', '')
  branch = branch.gsub(/\(HEAD detached at (.*)\)$/, '\1') if /\(HEAD detached at (.*)\)$/.match?(branch)
  branch
end
git(arg) click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 12
def self.git(arg)
  if Gem.win_platform?
    `\"#{GIT_EXECUTABLE}\" #{arg}`
  else
    `#{GIT_EXECUTABLE} #{arg}`
  end
end
modified_files() click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 72
def self.modified_files
  modified_files = `git diff --name-status #{Config.base_branch} #{Config.feature_branch}`
  modified_files.split("\n").filter_map do |line|
    next if line.start_with?('D')

    file_name = line.split("\t")[1]
    file_name
  end
end
supported?() click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 24
def self.supported?
  git('branch 2>&1') && $CHILD_STATUS.success?
end
switch_branch(branch) click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 59
def self.switch_branch(branch)
  dirty = !uncommitted_changes.empty?
  abort("Uncommitted changes are present: #{uncommitted_changes}") if dirty

  git("checkout #{branch}")
end
to_s() click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 28
def self.to_s
  'Git'
end
uncommitted_changes() click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 66
def self.uncommitted_changes
  return @uncommitted_changes if defined? @uncommitted_changes

  @uncommitted_changes = git('diff-index HEAD --').chomp! || ''
end

Public Instance Methods

churn() click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 32
def churn
  @churn ||= Churn.new(churn_after: Config.churn_after, paths: Config.paths)
end
date_of_last_commit(path) click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 40
def date_of_last_commit(path)
  churn.date_of_last_commit(path)
end
git(arg) click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 20
def git(arg)
  self.class.git(arg)
end
head_reference() click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 48
def head_reference
  git('rev-parse --verify HEAD').chomp!
end
revision?() click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 44
def revision?
  head_reference && $CHILD_STATUS.success?
end
revisions_count(path) click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 36
def revisions_count(path)
  churn.revisions_count(path)
end
travel_to_head() { || ... } click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 52
def travel_to_head
  stash_successful = stash_changes
  yield
ensure
  travel_to_original_state if stash_successful
end

Private Instance Methods

stash_changes() click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 91
def stash_changes
  stashes_count_before = stashes_count
  git('stash')
  stashes_count_after = stashes_count
  stashes_count_after > stashes_count_before
end
stashes_count() click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 98
def stashes_count
  git('stash list --format=%h').count("\n")
end
travel_to_original_state() click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 102
def travel_to_original_state
  git('stash pop')
end