Class: FeaturesReport::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/features_report/git.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files) ⇒ Git

Returns a new instance of Git.



15
16
17
18
# File 'lib/features_report/git.rb', line 15

def initialize(files)
  @repo = Grit::Repo.new(Git.git_repo?(files.first))
  @files = files
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



29
30
31
# File 'lib/features_report/git.rb', line 29

def files
  @files
end

Class Method Details

.git_repo?(filename) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
12
13
# File 'lib/features_report/git.rb', line 4

def self.git_repo?(filename)
  path = File.expand_path(filename)
  while path and path != ""
    if File.exist?(path + "/.git")
      return path
    end
    path = path.split("/")[0..-2].join("/")
  end
  false
end

Instance Method Details

#git_dirObject



20
21
22
# File 'lib/features_report/git.rb', line 20

def git_dir
  @repo.path.split("/")[0..-2].join("/")
end

#last_commit(feature) ⇒ Object



24
25
26
27
# File 'lib/features_report/git.rb', line 24

def last_commit(feature)
  filename = File.expand_path(feature.file, git_dir).gsub(/^#{Regexp.escape(git_dir)}\//, "")
  commit = @repo.log(@repo.head.name, filename).first
end