Skip to content

Commit

Permalink
Extract Git::Patches#find_line from Git::Line
Browse files Browse the repository at this point in the history
  • Loading branch information
mmozuras committed Sep 10, 2014
1 parent d4cb558 commit b2575d7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
9 changes: 2 additions & 7 deletions lib/pronto/git/line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@ def commit_line
@commit_line ||= begin
patches = patch.repo.show_commit(commit_sha)

commit_patch = patches.find do |p|
patch.new_file_full_path == p.new_file_full_path
end

lines = commit_patch ? commit_patch.lines : []
result = lines.find { |l| blame[:orig_start_line_number] == l.new_lineno }

result = patches.find_line(patch.new_file_full_path,
blame[:orig_start_line_number])
result || self # no commit_line means that it was just added
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/pronto/git/patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ def initialize(repo, commit, patches)
def each(&block)
@patches.each(&block)
end

def find_line(path, line)
patch = find { |p| p.new_file_full_path == path }
lines = patch ? patch.lines : []
lines.find { |l| l.new_lineno == line }
end
end
end
end
22 changes: 22 additions & 0 deletions spec/pronto/git/patches_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'spec_helper'

module Pronto
module Git
describe Patches do
describe '#find_line' do
subject { Patches.new(repo, commit, patches).find_line(path, line) }

let(:repo) { nil }
let(:commit) { nil }

let(:path) { '/test.rb' }
let(:line) { 1 }

context 'no patches' do
let(:patches) { [] }
it { should be_nil }
end
end
end
end
end

0 comments on commit b2575d7

Please sign in to comment.