Class: GitEvolution::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/git_evolution/repository.rb

Instance Method Summary collapse

Constructor Details

#initialize(directory_name) ⇒ Repository

Returns a new instance of Repository.



3
4
5
# File 'lib/git_evolution/repository.rb', line 3

def initialize(directory_name)
  @git_repo = Rugged::Repository.discover(File.expand_path(directory_name))
end

Instance Method Details

#dirObject



7
8
9
# File 'lib/git_evolution/repository.rb', line 7

def dir
  @git_repo.workdir
end

#line_commits(start_line, end_line, file, since = nil) ⇒ Object



11
12
13
14
# File 'lib/git_evolution/repository.rb', line 11

def line_commits(start_line, end_line, file, since = nil)
  raw_results = raw_line_history(start_line, end_line, file, since)
  raw_results.split("\u0000").map { |raw_commit| Commit.new(raw_commit) }
end

#raw_line_history(start_line, end_line, file, since = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/git_evolution/repository.rb', line 16

def raw_line_history(start_line, end_line, file, since = nil)
  since_option = "--since '#{since}'"

  Dir.chdir(dir) do
    return `git --no-pager log -p -z\
    #{since_option if since}\
    #{"-L#{start_line},#{end_line}:#{file}" if start_line && end_line}\
    --follow #{file}`
  end
end