module Regtest::Git

Regtest plugin for git (results are checked automatically when running regtest)

Attributes

C[RW]

git parameter -C

git_dir[RW]

git parameter --git-dir

work_tree[RW]

git parameter --work-tree

Public Instance Methods

check_results() click to toggle source

Redefine Regtest.check_results.

# File lib/regtest/git.rb, line 16
def check_results
  output_files = Regtest.results.keys
  if Git.C || Git.work_tree
    output_files.map! {|fn| File.expand_path(fn)}
  end
  if output_files.empty?
    report "\nNothing to do.", type: :success
    return :success
  end
  git_status = ['git', git_global_args, %w(status -s --)].flatten
  git_results, stderr, _ = Open3.capture3(*git_status, *output_files)
  unless stderr.empty?
    report "\ngit command coud not be executed!", type: :fail
    return :fail
  end
  case git_results
  when /^.M/ # at least one modified file
    report "\nThere are changes in your sample results!", type: :fail
    system *git_status, *output_files
    return :fail
  when /^.\?/ # at least one unknown file
    report "\nThere is at least one new sample result file.", type: :unknown_result
    system *git_status, *output_files
    return :unknown_result
  when '', /^. / # no changes in (maybe staged) files
    report "\nLooks good. :)", type: :success
    system *git_status, *output_files
    return :success
  else
    report "\nYour sample results are in a bad condition!", type: :fail
    system *git_status, *output_files
    return :fail
  end
end

Private Instance Methods

git_global_args() click to toggle source
# File lib/regtest/git.rb, line 64
def git_global_args
  args = []
  if c = Regtest::Git.C
    args <<  '-C'
    args << c
  end
  if wt = Regtest::Git.work_tree
    args << format('--work-tree=%s', wt)
  end
  if gd = Regtest::Git.git_dir
    args << format('--git-dir=%s', gd)
  end
  args
end