class Lapidarist::GitCommand

Attributes

shell[R]

Public Class Methods

new() click to toggle source
# File lib/lapidarist/git_command.rb, line 3
def initialize
  @shell = Shell.new
end

Public Instance Methods

add(*files) click to toggle source
# File lib/lapidarist/git_command.rb, line 11
def add(*files)
  shell.run("git add #{files.join(' ')}")
end
bisect(start_sha, test) click to toggle source
# File lib/lapidarist/git_command.rb, line 19
def bisect(start_sha, test)
  Lapidarist.logger.header('Starting bisect')
  bisect_start(start_sha)
  bisect_run(start_sha, test)
end
clean?() click to toggle source
# File lib/lapidarist/git_command.rb, line 33
def clean?
  shell.run('[ -z "$(git status --porcelain=v1 -uno)" ]')[1] == 0
end
commit(message) click to toggle source
# File lib/lapidarist/git_command.rb, line 15
def commit(message)
  shell.run("git commit -m '#{message}' #{Lapidarist.config.commit_flags}".strip, label: 'git commit')
end
count_commits(start_sha, end_sha) click to toggle source
# File lib/lapidarist/git_command.rb, line 37
def count_commits(start_sha, end_sha)
  shell.run("git rev-list #{end_sha} ^#{start_sha} --count")[0].to_i
end
head() click to toggle source
# File lib/lapidarist/git_command.rb, line 7
def head
  shell.run('git rev-parse HEAD')[0].strip
end
log(sha) click to toggle source
# File lib/lapidarist/git_command.rb, line 25
def log(sha)
  shell.run("git log HEAD...#{sha}^ --no-color --oneline", label: 'git log')
end
reset_hard(ref) click to toggle source
# File lib/lapidarist/git_command.rb, line 29
def reset_hard(ref)
  shell.run("git reset --hard #{ref}")
end

Private Instance Methods

bisect_reset() click to toggle source
# File lib/lapidarist/git_command.rb, line 84
def bisect_reset
  shell.run('git bisect reset')
end
bisect_run(start_sha, test) click to toggle source
# File lib/lapidarist/git_command.rb, line 51
def bisect_run(start_sha, test)
  failing_gem_name = nil

  shell.run("git bisect run #{test}") do |std_out_err|
    while line = std_out_err.gets
      bisect_step = BisectStep.new(line, shell)

      if bisect_step.failure?
        failing_sha = bisect_step.failing_sha
        failing_gem_name = bisect_step.failing_gem(failing_sha)
        Lapidarist.logger.info("... found failing gem update: #{failing_gem_name}")
      end

      if bisect_step.success?
        bisect_reset
        rewind_to_last_good_commit(failing_sha)
      end
    end

    unless failing_gem_name
      Lapidarist.logger.info("... last commit was failing commit")
    end

    Lapidarist.logger.footer("bisect done")
  end

  if failing_gem_name && Lapidarist.config.debug
    log(start_sha)
  end

  failing_gem_name
end
bisect_start(sha) click to toggle source
# File lib/lapidarist/git_command.rb, line 45
def bisect_start(sha)
  shell.run('git bisect start')
  shell.run('git bisect bad')
  shell.run("git bisect good #{sha}", label: 'git bisect good')
end
rewind_to_last_good_commit(sha) click to toggle source
# File lib/lapidarist/git_command.rb, line 88
def rewind_to_last_good_commit(sha)
  reset_hard("#{sha}^")
end