Class: Bob::Test::GitRepo

Inherits:
AbstractSCMRepo show all
Defined in:
lib/bob/test/scm/git.rb

Instance Attribute Summary

Attributes inherited from AbstractSCMRepo

#name, #path

Instance Method Summary collapse

Methods inherited from AbstractSCMRepo

#add_commit, #add_failing_commit, #add_successful_commit, #initialize

Constructor Details

This class inherits a constructor from Bob::Test::AbstractSCMRepo

Instance Method Details

#commitsObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/bob/test/scm/git.rb', line 18

def commits
  Dir.chdir(path) do
    commits = `git log --pretty=oneline`.collect { |l| l.split(" ").first }
    commits.inject([]) do |commits, sha1|
      format  = "---%nmessage: >-%n  %s%ntimestamp: %ci%n" +
        "identifier: %H%nauthor: %n name: %an%n email: %ae%n"
      commits << YAML.load(`git show -s --pretty=format:"#{format}" #{sha1}`)
    end.reverse
  end
end

#createObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/bob/test/scm/git.rb', line 5

def create
  FileUtils.mkdir(path)

  Dir.chdir(path) do
    run "git init"
    run "git config user.name 'John Doe'"
    run "git config user.email '[email protected]'"
    run "echo 'just a test repo' >> README"
    add "README"
    commit "First commit"
  end
end

#headObject



29
30
31
32
33
# File 'lib/bob/test/scm/git.rb', line 29

def head
  Dir.chdir(path) do
    `git log --pretty=format:%H | head -1`.chomp
  end
end

#short_headObject



35
36
37
# File 'lib/bob/test/scm/git.rb', line 35

def short_head
  head[0..6]
end