lib/gitlab_git/diff.rb in gitlab_git-7.0.0.rc10 vs lib/gitlab_git/diff.rb in gitlab_git-7.0.0.rc11

- old
+ new

@@ -3,12 +3,10 @@ module Git class Diff class TimeoutError < StandardError; end include EncodingHelper - attr_accessor :raw_diff - # Diff properties attr_accessor :old_path, :new_path, :a_mode, :b_mode, :diff # Stats properties attr_accessor :new_file, :renamed_file, :deleted_file @@ -50,15 +48,17 @@ end hash end + def submodule? + a_mode == '160000' || b_mode == '160000' + end + private def init_from_rugged(rugged) - @raw_diff = rugged - @diff = encode!(strip_diff_headers(rugged.to_s)) d = rugged.delta @new_path = encode!(d.new_file[:path]) @old_path = encode!(d.old_file[:path]) @@ -78,12 +78,23 @@ end # Strip out the information at the beginning of the patch's text to match # Grit's output def strip_diff_headers(diff_text) - lines = diff_text.split("\n") - lines.shift until lines.empty? || lines.first.match("^(---|Binary)") - lines.join("\n") + # Delete everything up to the first line that starts with '---' or + # 'Binary' + diff_text.sub!(/\A.*?^(---|Binary)/m, '\1') + # Remove trailing newline because the tests ask for it + diff_text.chomp! + + if diff_text.start_with?('---') or diff_text.start_with?('Binary') + diff_text + else + # If the diff_text did not contain a line starting with '---' or + # 'Binary', return the empty string. No idea why; we are just + # preserving behavior from before the refactor. + '' + end end end end end