Class: Covered::Git::BranchChanges
- Inherits:
-
Object
- Object
- Covered::Git::BranchChanges
- Defined in:
- lib/covered/git/branch_changes.rb
Instance Method Summary collapse
- #default_branch ⇒ Object
-
#initialize(root) ⇒ BranchChanges
constructor
A new instance of BranchChanges.
-
#lines_modified(branch = nil) ⇒ Object
Compute the lines modified for a given branch, returning a hash of paths to a set of line numbers.
- #repository ⇒ Object
Constructor Details
#initialize(root) ⇒ BranchChanges
Returns a new instance of BranchChanges.
5 6 7 |
# File 'lib/covered/git/branch_changes.rb', line 5 def initialize(root) @root = root end |
Instance Method Details
#default_branch ⇒ Object
13 14 15 |
# File 'lib/covered/git/branch_changes.rb', line 13 def default_branch "main" end |
#lines_modified(branch = nil) ⇒ Object
Compute the lines modified for a given branch, returning a hash of paths to a set of line numbers.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/covered/git/branch_changes.rb', line 19 def lines_modified(branch = nil) branch ||= default_branch result = Hash.new{|k,v| k[v] = Set.new} diff = repository.diff(repository.rev_parse(branch), repository.last_commit) diff.each_patch do |patch| path = patch.delta.new_file[:path] patch.each_hunk do |hunk| hunk.each_line do |line| result[path] << line.new_lineno if line.addition? end end end result.default = nil return result.freeze end |
#repository ⇒ Object
9 10 11 |
# File 'lib/covered/git/branch_changes.rb', line 9 def repository @repository ||= Rugged::Repository.discover(@root) end |