class RubyCritic::SourceControlSystem::Git

Constants

GIT_EXECUTABLE

Public Class Methods

current_branch() click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 72
def self.current_branch
  branch_list = `git branch`
  branch_list.match(/\*.*$/)[0].gsub('* ', '')
end
git(arg) click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 11
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 62
def self.modified_files
  modified_files = `git diff --name-status #{Config.base_branch} #{Config.feature_branch}`
  modified_files.split("\n").map do |line|
    next if line.start_with?('D')

    file_name = line.split("\t")[1]
    file_name
  end.compact
end
supported?() click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 23
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 54
def self.switch_branch(branch)
  uncommitted_changes? ? abort('Uncommitted changes are present.') : `git checkout #{branch}`
end
to_s() click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 27
def self.to_s
  'Git'
end
uncommitted_changes?() click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 58
def self.uncommitted_changes?
  !`git diff-index HEAD --`.empty?
end

Public Instance Methods

date_of_last_commit(path) click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 35
def date_of_last_commit(path)
  git("log -1 --date=iso --format=%ad #{path.shellescape}").chomp!
end
git(arg) click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 19
def git(arg)
  self.class.git(arg)
end
head_reference() click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 43
def head_reference
  git('rev-parse --verify HEAD').chomp!
end
revision?() click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 39
def revision?
  head_reference && $CHILD_STATUS.success?
end
revisions_count(path) click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 31
def revisions_count(path)
  git("log --follow --format=%h #{path.shellescape}").count("\n")
end
travel_to_head() { || ... } click to toggle source
# File lib/rubycritic/source_control_systems/git.rb, line 47
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 79
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 86
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 90
def travel_to_original_state
  git('stash pop')
end