Class: Bob::Test::GitRepo

Inherits:
AbstractRepo show all
Defined in:
lib/bob/test/repo.rb

Instance Method Summary collapse

Methods inherited from AbstractRepo

#add_commit, #add_failing_commit, #add_successful_commit, #command, #initialize, #script, #short_head

Constructor Details

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

Instance Method Details

#add(file) ⇒ Object



71
72
73
# File 'lib/bob/test/repo.rb', line 71

def add(file)
  `git add #{file}`
end

#branchObject



63
64
65
# File 'lib/bob/test/repo.rb', line 63

def branch
  "master"
end

#commit(message) ⇒ Object



75
76
77
# File 'lib/bob/test/repo.rb', line 75

def commit(message)
  `git commit -m "#{message}"`
end

#commitsObject



95
96
97
98
99
100
101
102
103
104
# File 'lib/bob/test/repo.rb', line 95

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

#createObject



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/bob/test/repo.rb', line 83

def create
  FileUtils.mkdir(@path)

  Dir.chdir(@path) {
    `git init`
    `git config user.name 'John Doe'`
    `git config user.email '[email protected]'`
  }

  super
end

#headObject



79
80
81
# File 'lib/bob/test/repo.rb', line 79

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

#scmObject



59
60
61
# File 'lib/bob/test/repo.rb', line 59

def scm
  "git"
end

#uriObject



67
68
69
# File 'lib/bob/test/repo.rb', line 67

def uri
  @path
end