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


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

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

#branchObject


54
55
56
# File 'lib/pronto/git/repository.rb', line 54

def branch
  @repo.head.name.sub('refs/heads/', '') if @repo.head.branch?
end

#commits_until(sha) ⇒ Object


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

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, options = nil) ⇒ Object


10
11
12
13
14
15
16
17
18
19
# File 'lib/pronto/git/repository.rb', line 10

def diff(commit, options = nil)
  if commit == :index
    patches = @repo.index.diff(options)
    Patches.new(self, head, patches)
  else
    merge_base = merge_base(commit)
    patches = @repo.diff(merge_base, head, options)
    Patches.new(self, merge_base, patches)
  end
end

#pathObject


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

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

#remote_urlsObject


58
59
60
# File 'lib/pronto/git/repository.rb', line 58

def remote_urls
  @repo.remotes.map(&:url)
end

#show_commit(sha) ⇒ Object


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

def show_commit(sha)
  return empty_patches(sha) unless sha

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

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

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