Module: Git::Autobisect

Defined in:
lib/git/autobisect.rb,
lib/git/autobisect/version.rb

Constant Summary collapse

VERSION =
Version = "0.3.1"

Class Method Summary collapse

Class Method Details

.cli(argv) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/git/autobisect.rb', line 6

def cli(argv)
  options = extract_options(argv)

  command = argv.first
  if command.to_s.empty?
    puts "Usage instructions: git-autobisect --help"
    return 1
  end

  # make sure bundle is fresh before each run
  if File.exist?("Gemfile")
    command = "(bundle check || (test -f vendor/cache && bundle --local --quiet) || bundle --quiet) && (#{command})"
  end

  # reset changes but keep the exit status
  command += "; export X=$? ; git reset --hard ; exit $X"

  run_command(command, options) || 0
end

.run_command(command, options) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/git/autobisect.rb', line 26

def run_command(command, options)
  commits = `git log --pretty=format:'%h' | head -n #{options[:max]}`.split("\n")
  good, bad = find_good_and_bad_commit(commits, command, options)

  if good == commits.first
    puts " ---> HEAD is not broken"
    return 1
  elsif not good
    puts " ---> No good commit found before HEAD~#{options[:max]}"
    return 1
  end

  if exact_commit_known?(commits, good, bad)
    # return same result as git bisect
    run! "git checkout #{bad}"
    puts "#{bad} is the first bad commit"
    puts `git show #{bad}`
  else
    first_bad = bisect_to_exact_match(command, good, bad)
    run! "git checkout #{first_bad}"
  end
end