Class: Pronto::Git::Repository

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

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Repository

Returns a new instance of Repository.



6
7
8
# File 'lib/pronto/git/repository.rb', line 6

def initialize(path)
  @repo = Rugged::Repository.new(path)
end

Instance Method Details

#blame(patch, lineno) ⇒ Object



46
47
48
49
50
51
# File 'lib/pronto/git/repository.rb', line 46

def blame(patch, lineno)
  Rugged::Blame.new(@repo, patch.delta.new_file[:path],
                    min_line: lineno, max_line: lineno,
                    track_copies_same_file: true,
                    track_copies_any_commit_copies: true)[0]
end

#commits_until(sha) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/pronto/git/repository.rb', line 33

def commits_until(sha)
  result = []
  @repo.walk(head, Rugged::SORT_TOPO).take_while do |commit|
    result << commit.oid
    !commit.oid.start_with?(sha)
  end
  result
end

#diff(commit) ⇒ Object



14
15
16
17
18
# File 'lib/pronto/git/repository.rb', line 14

def diff(commit)
  merge_base = merge_base(commit)
  patches = @repo.diff(merge_base, head)
  Patches.new(self, merge_base, patches)
end

#github_slugObject



10
11
12
# File 'lib/pronto/git/repository.rb', line 10

def github_slug
  remotes.map(&:github_slug).compact.first
end

#pathObject



42
43
44
# File 'lib/pronto/git/repository.rb', line 42

def path
  Pathname.new(@repo.path).parent
end

#show_commit(sha) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pronto/git/repository.rb', line 20

def show_commit(sha)
  return [] unless sha

  commit = @repo.lookup(sha)
  return [] if commit.parents.count != 1

  # TODO: Rugged does not seem to support diffing against multiple parents
  diff = commit.diff(reverse: true)
  return [] if diff.nil?

  Patches.new(self, sha, diff.patches)
end