-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpatch.rb
executable file
·37 lines (31 loc) · 1.01 KB
/
patch.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'rubygems'
require 'logger'
require 'rugged'
require 'git'
class Patch
attr_reader :additions
attr_reader :deletions
attr_reader :changes
def initialize()
@changes = nil
@additions = nil
@deletions = nil
end
def initialize(patch)
@changes = patch
self.patch_breakdown
end
def patch_breakdown()
# Get the string from the MatchData returned by Regex.match
@additions = (@changes).match(/^[\+][^+].*/).to_s
@deletions = (@changes).match(/^[\-][^-].*/).to_s
@additions[0] = ""
@deletions[0] = ""
# Assert commented for corner case, so that they are handled properly:
# diff --git a/django-docs/images/flatfiles_admin.png b/django-docs/images/flatfiles_admin.png
# new file mode 100644
# index 0000000..391a629
# Binary files /dev/null and b/django-docs/images/flatfiles_admin.png differ
# raise "Commit patch info READ FAILURE" unless @additions.to_s.size != 0 || @deletions.to_s.size != 0
end
end