Class: Pronto::Git::Repository
- Inherits:
-
Object
- Object
- Pronto::Git::Repository
- Defined in:
- lib/pronto/git/repository.rb
Instance Method Summary collapse
- #blame(path, lineno) ⇒ Object
- #branch ⇒ Object
- #commits_until(sha) ⇒ Object
- #diff(commit, options = nil) ⇒ Object
- #head_commit_sha ⇒ Object
-
#initialize(path) ⇒ Repository
constructor
A new instance of Repository.
- #path ⇒ Object
- #remote_urls ⇒ Object
- #show_commit(sha) ⇒ Object
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(path, lineno) ⇒ Object
47 48 49 50 51 |
# File 'lib/pronto/git/repository.rb', line 47 def blame(path, lineno) Rugged::Blame.new(@repo, path, min_line: lineno, max_line: lineno, track_copies_same_file: true, track_copies_any_commit_copies: true)[0] end |
#branch ⇒ Object
53 54 55 |
# File 'lib/pronto/git/repository.rb', line 53 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, = nil) if commit == :index patches = @repo.index.diff() Patches.new(self, head, patches) else merge_base = merge_base(commit) patches = @repo.diff(merge_base, head, ) Patches.new(self, merge_base, patches) end end |
#head_commit_sha ⇒ Object
61 62 63 |
# File 'lib/pronto/git/repository.rb', line 61 def head_commit_sha head.oid end |
#path ⇒ Object
43 44 45 |
# File 'lib/pronto/git/repository.rb', line 43 def path Pathname.new(@repo.path).parent end |
#remote_urls ⇒ Object
57 58 59 |
# File 'lib/pronto/git/repository.rb', line 57 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 |