Module: MissCleo::DiffDetector

Defined in:
lib/miss_cleo/diff_detector.rb

Class Method Summary collapse

Class Method Details

.lines_changedObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/miss_cleo/diff_detector.rb', line 4

def lines_changed
  Set.new.tap do |changed_lines|
    repo = Rugged::Repository.new '.'
    repo.index.diff.each_patch do |patch|
      file = patch.delta.old_file[:path]

      patch.each_hunk do |hunk|
        hunk.each_line do |line|
          case line.line_origin
          when :addition
            changed_lines << [file, line.new_lineno] unless exclude_from_map?(file)
          when :deletion
            changed_lines << [file, line.old_lineno] unless exclude_from_map?(file)
          when :context
            # do nothing
          end
        end
      end
    end

  end
end