Skip to content

Commit

Permalink
Merge pull request #111 from glennsarti/ticket/maint/monkey_path_git_gem
Browse files Browse the repository at this point in the history
Monkey Patch git ruby gem
  • Loading branch information
rnelson0 authored Feb 23, 2017
2 parents 899483f + 55bd5ae commit 7ddc50d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ AllCops:
- 'vendor/**/*'
- 'tmp/**/*'
- 'pkg/**/*'
- 'lib/monkey_patches.rb'

Style/HashSyntax:
Enabled: false
Expand Down
1 change: 1 addition & 0 deletions lib/modulesync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'modulesync/renderer'
require 'modulesync/settings'
require 'modulesync/util'
require 'monkey_patches'

module ModuleSync
include Constants
Expand Down
40 changes: 40 additions & 0 deletions lib/monkey_patches.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module Git
class Diff
# Monkey patch process_full_diff until https://github.com/schacon/ruby-git/issues/326 is resolved
def process_full_diff
defaults = {
:mode => '',
:src => '',
:dst => '',
:type => 'modified'
}
final = {}
current_file = nil
full_diff_utf8_encoded = @full_diff.encode("UTF-8", "binary", {
:invalid => :replace,
:undef => :replace
})
full_diff_utf8_encoded.split("\n").each do |line|
if m = /^diff --git a\/(.*?) b\/(.*?)/.match(line)
current_file = m[1]
final[current_file] = defaults.merge({:patch => line, :path => current_file})
elsif !current_file.nil?
if m = /^index (.......)\.\.(.......)( ......)*/.match(line)
final[current_file][:src] = m[1]
final[current_file][:dst] = m[2]
final[current_file][:mode] = m[3].strip if m[3]
end
if m = /^([[:alpha:]]*?) file mode (......)/.match(line)
final[current_file][:type] = m[1]
final[current_file][:mode] = m[2]
end
if m = /^Binary files /.match(line)
final[current_file][:binary] = true
end
final[current_file][:patch] << "\n" + line
end
end
final.map { |e| [e[0], DiffFile.new(@base, e[1])] }
end
end
end

0 comments on commit 7ddc50d

Please sign in to comment.