Module: Gnurr::Git
- Includes:
- Helper
- Included in:
- Linter
- Defined in:
- lib/gnurr/git.rb
Overview
For handling/reading Git output
Instance Method Summary
collapse
Methods included from Helper
#array_to_ranges, #escaped_filename, #left_bump, #log_error, #severity_color
Instance Method Details
8
9
10
11
12
13
|
# File 'lib/gnurr/git.rb', line 8
def (diffs)
diffs.map do |lines|
nums = lines.match(/^.+\+(?<from>[0-9]+)(,(?<len>[0-9]+))? .+$/)
Range.new(nums[:from].to_i, nums[:from].to_i + nums[:len].to_i)
end.map(&:to_a).flatten
end
|
#file_diffs(file) ⇒ Object
24
25
26
27
28
|
# File 'lib/gnurr/git.rb', line 24
def file_diffs(file)
diffs = `git diff --unified=0 #{@options[:base]} #{escaped_filename(file)} \
| egrep '\\+[0-9]+(,[1-9][0-9]*)? '`
(diffs.split("\n"))
end
|
#full_file_diff ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/gnurr/git.rb', line 15
def full_file_diff
return @diff if @diff
path = @options[:path].nil? || !@options[:path].any? ? '' : "-- #{@options[:path].map { |p| escaped_filename(p) }.join(' ')}"
diff = `git diff #{@options[:base]} --name-only --diff-filter=ACMRTUXB #{path}`
.split("\n")
.map { |file| [file, file_diffs(file)] }
@diff = Hash[diff.select { |_k, v| v && v.any? }]
end
|