diff --git a/lib/pronto/git/line.rb b/lib/pronto/git/line.rb index e306fc47..7ac1fa0b 100644 --- a/lib/pronto/git/line.rb +++ b/lib/pronto/git/line.rb @@ -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 diff --git a/lib/pronto/git/patches.rb b/lib/pronto/git/patches.rb index 041b6cb4..faef168d 100644 --- a/lib/pronto/git/patches.rb +++ b/lib/pronto/git/patches.rb @@ -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 diff --git a/spec/pronto/git/patches_spec.rb b/spec/pronto/git/patches_spec.rb new file mode 100644 index 00000000..8bf8c6a4 --- /dev/null +++ b/spec/pronto/git/patches_spec.rb @@ -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