Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monkey Patch git ruby gem #111

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some funky alignment here.

Copy link
Contributor Author

@glennsarti glennsarti Feb 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah...That was a copy-n-paste from the git ruby gem. It has a combo of spaces and tabs :-( I was in two minds to fix it. I went with to keep it the same as the original as much as possible so it's easier to see where the patch is by comparing this code and the original.

However I'm happy to go through it and modify the alignments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's from the original it makes sense to keep it.

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