gem-patch 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +17 -7
- data/lib/rubygems/commands/patch_command.rb +22 -6
- data/lib/rubygems/patcher.rb +11 -7
- data/rakefile.rb +4 -4
- data/test/rubygems/test_gem_patch.rb +135 -7
- metadata +14 -18
- data/README.rdoc +0 -25
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c8184438e8bca43220120c8d713c90c563bfcfd4
|
4
|
+
data.tar.gz: 7f0602aa71171948d2e6bfa09f037fd819406d9a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5a4c0e65496e12db4179f0dccd295392f6ea96e16385fb6a8e9749e3f0513e34bcc8d3fafc4166078d6c0ca54dec0fcb3331d1fcb5d41a12ed288d9137c2e492
|
7
|
+
data.tar.gz: 302768e47f9212575d9830f2fb11d14313dc0658be3fb184038f074c41b0611ddac5046f5a2eb2a08e32f74cc3f0cf8ec6bc102267415e6e2f7cc6061bcf134a
|
data/README.md
CHANGED
@@ -4,21 +4,31 @@ A RubyGems plugin that patches gems.
|
|
4
4
|
|
5
5
|
## Description
|
6
6
|
|
7
|
-
`gem-patch` is a RubyGems plugin that helps to patch gems without manually opening and rebuilding them. It opens a given
|
7
|
+
`gem-patch` is a RubyGems plugin that helps to patch gems without manually opening and rebuilding them. It opens a given `.gem` file, extracts it, patches it with system `patch` command, clones its spec, updates the file list and builds the patched gem.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
|
-
Run
|
12
|
-
|
11
|
+
Run `gem install gem-patch` and you are done.
|
12
|
+
|
13
|
+
### Fedora
|
14
|
+
|
15
|
+
On Fedora you can use YUM:
|
16
|
+
|
17
|
+
`sudo yum install rubygem-gem-patch`
|
13
18
|
|
14
19
|
## Usage
|
15
20
|
|
16
21
|
`gem patch [options] name-version.gem PATCH [PATCH ...]`
|
17
22
|
|
18
|
-
|
23
|
+
### Supported options
|
19
24
|
|
20
|
-
|
21
|
-
|
25
|
+
| option | alternative syntax | description |
|
26
|
+
| ------ | ------ | ------ |
|
27
|
+
| -pNUMBER | --strip-numberNUMBER | Sets the file name strip count to NUMBER. |
|
28
|
+
| -FNUMBER | --fuzz=NUMBER | Set NUMBER of lines to ignore in looking for places to install a hunk. |
|
29
|
+
| -oFILE | --output=FILE | Set output FILE. |
|
30
|
+
| --dry-run | | Print the results from patching, but do not change any files. |
|
31
|
+
| --verbose | | Print additional info and STDOUT from `patch` command. |
|
22
32
|
|
23
33
|
## Requirements
|
24
34
|
|
@@ -26,4 +36,4 @@ This version is build for both RubyGems 1.8 and RubyGems 2.0.
|
|
26
36
|
|
27
37
|
## Copyright
|
28
38
|
|
29
|
-
|
39
|
+
Released under the MIT license. Feel free to contribute!
|
@@ -10,6 +10,21 @@ class Gem::Commands::PatchCommand < Gem::Command
|
|
10
10
|
add_option('-pNUMBER', '--strip=NUMBER', 'Set the file name strip count to NUMBER.') do |number, options|
|
11
11
|
options[:strip] = number
|
12
12
|
end
|
13
|
+
|
14
|
+
# Number of lines to ignore in looking for places to install a hunk
|
15
|
+
add_option('-FNUMBER', '--fuzz=NUMBER', 'Set NUMBER of lines to ignore in looking for places to install a hunk.') do |number, options|
|
16
|
+
options[:fuzz] = number
|
17
|
+
end
|
18
|
+
|
19
|
+
# Set output file to FILE instead of overwritting
|
20
|
+
add_option('-oFILE', '--output=FILE', 'Set output FILE.') do |file, options|
|
21
|
+
options[:outfile] = file
|
22
|
+
end
|
23
|
+
|
24
|
+
# Dry run only shows expected output from the patching process
|
25
|
+
add_option('--dry-run', 'Print the results from patching, but do not change any files.') do |file, options|
|
26
|
+
options[:dry_run] = true
|
27
|
+
end
|
13
28
|
end
|
14
29
|
|
15
30
|
def arguments # :nodoc:
|
@@ -21,11 +36,12 @@ class Gem::Commands::PatchCommand < Gem::Command
|
|
21
36
|
end
|
22
37
|
|
23
38
|
def description # :nodoc:
|
24
|
-
<<-EOF
|
25
|
-
|
26
|
-
|
27
|
-
|
39
|
+
desc = <<-EOF
|
40
|
+
`gem-patch` is a RubyGems plugin that helps to patch gems without manually opening and rebuilding them.
|
41
|
+
It opens a given .gem file, extracts it, patches it with system `patch` command,
|
42
|
+
clones its spec, updates the file list and builds the patched gem.
|
28
43
|
EOF
|
44
|
+
return desc.gsub(/^\s+/, '')
|
29
45
|
end
|
30
46
|
|
31
47
|
def usage # :nodoc:
|
@@ -49,7 +65,7 @@ class Gem::Commands::PatchCommand < Gem::Command
|
|
49
65
|
end
|
50
66
|
|
51
67
|
patcher = Gem::Patcher.new(gemfile, options[:output])
|
52
|
-
patcher.patch_with(patches, options
|
68
|
+
patcher.patch_with(patches, options)
|
53
69
|
patcher.print_results
|
54
70
|
end
|
55
|
-
end
|
71
|
+
end
|
data/lib/rubygems/patcher.rb
CHANGED
@@ -24,7 +24,7 @@ class Gem::Patcher
|
|
24
24
|
##
|
25
25
|
# Patch the gem, move the new patched gem to the working directory and return the path
|
26
26
|
|
27
|
-
def patch_with(patches,
|
27
|
+
def patch_with(patches, options)
|
28
28
|
@output = []
|
29
29
|
|
30
30
|
check_patch_command_is_installed
|
@@ -33,25 +33,29 @@ class Gem::Patcher
|
|
33
33
|
# Apply all patches
|
34
34
|
patches.each do |patch|
|
35
35
|
info 'Applying patch ' + patch
|
36
|
-
apply_patch(patch,
|
36
|
+
apply_patch(patch, options)
|
37
37
|
end
|
38
38
|
|
39
39
|
build_patched_gem
|
40
40
|
|
41
|
-
|
42
|
-
FileUtils.mv((File.join @target_dir, @package.spec.file_name),
|
41
|
+
options[:outfile] ||= File.join(@output_dir, @package.spec.file_name)
|
42
|
+
FileUtils.mv((File.join @target_dir, @package.spec.file_name), options[:outfile])
|
43
43
|
|
44
44
|
# Return the path to the patched gem
|
45
|
-
|
45
|
+
options[:outfile]
|
46
46
|
end
|
47
47
|
|
48
|
-
def apply_patch(patch,
|
48
|
+
def apply_patch(patch, options)
|
49
|
+
options[:strip] ||= 1
|
50
|
+
options[:fuzz] ||= 2
|
51
|
+
dry_run = '--dry-run' if options[:dry_run]
|
52
|
+
|
49
53
|
patch_path = File.expand_path(patch)
|
50
54
|
info 'Path to the patch to apply: ' + patch_path
|
51
55
|
|
52
56
|
# Apply the patch by calling 'patch -pNUMBER < patch'
|
53
57
|
Dir.chdir @target_dir do
|
54
|
-
IO.popen("patch --verbose -p#{
|
58
|
+
IO.popen("patch --verbose -p#{options[:strip]} --fuzz=#{options[:fuzz]} #{dry_run} < #{patch_path} 2>&1") do |out|
|
55
59
|
std = out.readlines
|
56
60
|
out.close
|
57
61
|
info std
|
data/rakefile.rb
CHANGED
@@ -4,7 +4,7 @@ require 'rdoc/task'
|
|
4
4
|
|
5
5
|
gemspec = Gem::Specification.new do |s|
|
6
6
|
s.name = "gem-patch"
|
7
|
-
s.version = "0.1.
|
7
|
+
s.version = "0.1.4"
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.summary = "RubyGems plugin for patching gems."
|
10
10
|
s.description = <<-EOF
|
@@ -18,7 +18,7 @@ gemspec = Gem::Specification.new do |s|
|
|
18
18
|
s.email = "jstribny@redhat.com"
|
19
19
|
s.required_ruby_version = ">= 1.8.7"
|
20
20
|
s.required_rubygems_version = ">= 1.8.0"
|
21
|
-
s.files = FileList["README.md", "
|
21
|
+
s.files = FileList["README.md", "LICENCE", "rakefile.rb",
|
22
22
|
"lib/**/*.rb", "test/**/test*.rb"]
|
23
23
|
end
|
24
24
|
|
@@ -26,8 +26,8 @@ Gem::PackageTask.new gemspec do |pkg|
|
|
26
26
|
end
|
27
27
|
|
28
28
|
Rake::RDocTask.new do |rd|
|
29
|
-
rd.main = "README.
|
30
|
-
rd.rdoc_files.include("README.
|
29
|
+
rd.main = "README.md"
|
30
|
+
rd.rdoc_files.include("README.md", "lib/**/*.rb")
|
31
31
|
end
|
32
32
|
|
33
33
|
Rake::TestTask.new('test') do |t|
|
@@ -8,6 +8,102 @@ class TestGemPatch < Gem::TestCase
|
|
8
8
|
@gems_dir = File.join @tempdir, 'gems'
|
9
9
|
@lib_dir = File.join @tempdir, 'gems', 'lib'
|
10
10
|
FileUtils.mkdir_p @lib_dir
|
11
|
+
|
12
|
+
# Defaults
|
13
|
+
@options = {}
|
14
|
+
@options[:strip] = 1
|
15
|
+
@options[:fuzz] = 2
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Test dry run is not supposed to change anything
|
20
|
+
|
21
|
+
def test_dry_run
|
22
|
+
@options[:dry_run] = true
|
23
|
+
|
24
|
+
gemfile = bake_testing_gem
|
25
|
+
|
26
|
+
patches = []
|
27
|
+
patches << bake_change_file_patch
|
28
|
+
|
29
|
+
# Creates new patched gem in @gems_dir
|
30
|
+
patcher = Gem::Patcher.new(gemfile, @gems_dir)
|
31
|
+
patched_gem = patcher.patch_with(patches, @options)
|
32
|
+
|
33
|
+
# Unpack
|
34
|
+
package = Gem::Package.new patched_gem
|
35
|
+
package.extract_files @gems_dir
|
36
|
+
|
37
|
+
# Still the same
|
38
|
+
assert_equal original_file, file_contents('foo.rb')
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Test using outfile for output
|
43
|
+
|
44
|
+
def test_use_outfile_for_output
|
45
|
+
@options[:outfile] = 'outfile.gem'
|
46
|
+
|
47
|
+
gemfile = bake_testing_gem
|
48
|
+
|
49
|
+
patches = []
|
50
|
+
patches << bake_change_file_patch
|
51
|
+
|
52
|
+
# Creates new patched gem in @gems_dir
|
53
|
+
patcher = Gem::Patcher.new(gemfile, @gems_dir)
|
54
|
+
patched_gem = patcher.patch_with(patches, @options)
|
55
|
+
|
56
|
+
assert_equal patched_gem, 'outfile.gem'
|
57
|
+
|
58
|
+
# Unpack
|
59
|
+
package = Gem::Package.new patched_gem
|
60
|
+
package.extract_files @gems_dir
|
61
|
+
|
62
|
+
assert_equal patched_file, file_contents('foo.rb')
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# Test changing a file in a gem with -F0 option
|
67
|
+
|
68
|
+
def test_should_not_patch_without_fuzz
|
69
|
+
@options[:fuzz] = 0
|
70
|
+
|
71
|
+
gemfile = bake_testing_gem
|
72
|
+
|
73
|
+
patches = []
|
74
|
+
patches << bake_change_file_with_fuzz_patch
|
75
|
+
|
76
|
+
# Creates new patched gem in @gems_dir
|
77
|
+
patcher = Gem::Patcher.new(gemfile, @gems_dir)
|
78
|
+
patched_gem = patcher.patch_with(patches, @options)
|
79
|
+
|
80
|
+
# Unpack
|
81
|
+
package = Gem::Package.new patched_gem
|
82
|
+
package.extract_files @gems_dir
|
83
|
+
|
84
|
+
assert_equal (patched_file == file_contents('foo.rb')), false
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
# Test changing a file in a gem with -F2 option
|
89
|
+
|
90
|
+
def test_change_file_with_fuzz_patch
|
91
|
+
@options[:fuzz] = 2
|
92
|
+
|
93
|
+
gemfile = bake_testing_gem
|
94
|
+
|
95
|
+
patches = []
|
96
|
+
patches << bake_change_file_with_fuzz_patch
|
97
|
+
|
98
|
+
# Creates new patched gem in @gems_dir
|
99
|
+
patcher = Gem::Patcher.new(gemfile, @gems_dir)
|
100
|
+
patched_gem = patcher.patch_with(patches, @options)
|
101
|
+
|
102
|
+
# Unpack
|
103
|
+
package = Gem::Package.new patched_gem
|
104
|
+
package.extract_files @gems_dir
|
105
|
+
|
106
|
+
assert_equal patched_file, file_contents('foo.rb')
|
11
107
|
end
|
12
108
|
|
13
109
|
##
|
@@ -21,7 +117,7 @@ class TestGemPatch < Gem::TestCase
|
|
21
117
|
|
22
118
|
# Creates new patched gem in @gems_dir
|
23
119
|
patcher = Gem::Patcher.new(gemfile, @gems_dir)
|
24
|
-
patched_gem = patcher.patch_with(patches,
|
120
|
+
patched_gem = patcher.patch_with(patches, @options)
|
25
121
|
|
26
122
|
# Unpack
|
27
123
|
package = Gem::Package.new patched_gem
|
@@ -34,14 +130,16 @@ class TestGemPatch < Gem::TestCase
|
|
34
130
|
# Test adding a file into a gem with -p0 option
|
35
131
|
|
36
132
|
def test_new_file_patch
|
133
|
+
@options[:strip] = 0
|
134
|
+
|
37
135
|
gemfile = bake_testing_gem
|
38
136
|
|
39
137
|
patches = []
|
40
138
|
patches << bake_new_file_patch
|
41
139
|
|
42
|
-
# Create a new patched gem in @
|
140
|
+
# Create a new patched gem in @gems_dir
|
43
141
|
patcher = Gem::Patcher.new(gemfile, @gems_dir)
|
44
|
-
patched_gem = patcher.patch_with(patches,
|
142
|
+
patched_gem = patcher.patch_with(patches, @options)
|
45
143
|
|
46
144
|
# Unpack
|
47
145
|
package = Gem::Package.new patched_gem
|
@@ -54,15 +152,17 @@ class TestGemPatch < Gem::TestCase
|
|
54
152
|
# Test adding and deleting a file in a gem with -p0 option
|
55
153
|
|
56
154
|
def test_delete_file_patch
|
155
|
+
@options[:strip] = 0
|
156
|
+
|
57
157
|
gemfile = bake_testing_gem
|
58
158
|
|
59
159
|
patches = []
|
60
160
|
patches << bake_new_file_patch
|
61
161
|
patches << bake_delete_file_patch
|
62
162
|
|
63
|
-
# Create a new patched gem in @
|
163
|
+
# Create a new patched gem in @gems_dir
|
64
164
|
patcher = Gem::Patcher.new(gemfile, @gems_dir)
|
65
|
-
patched_gem = patcher.patch_with(patches,
|
165
|
+
patched_gem = patcher.patch_with(patches, @options)
|
66
166
|
|
67
167
|
# Unpack
|
68
168
|
package = Gem::Package.new patched_gem
|
@@ -83,9 +183,9 @@ class TestGemPatch < Gem::TestCase
|
|
83
183
|
patches = []
|
84
184
|
patches << bake_incorrect_patch
|
85
185
|
|
86
|
-
# Create a new patched gem in @
|
186
|
+
# Create a new patched gem in @gems_dir
|
87
187
|
patcher = Gem::Patcher.new(gemfile, @gems_dir)
|
88
|
-
patched_gem = patcher.patch_with(patches,
|
188
|
+
patched_gem = patcher.patch_with(patches, @options)
|
89
189
|
|
90
190
|
# Unpack
|
91
191
|
package = Gem::Package.new patched_gem
|
@@ -104,6 +204,16 @@ class TestGemPatch < Gem::TestCase
|
|
104
204
|
|
105
205
|
patch_path
|
106
206
|
end
|
207
|
+
|
208
|
+
def bake_change_file_with_fuzz_patch
|
209
|
+
patch_path = File.join(@gems_dir, 'change_file_with_fuzz.patch')
|
210
|
+
|
211
|
+
File.open(patch_path, 'w') do |f|
|
212
|
+
f.write change_file_patch
|
213
|
+
end
|
214
|
+
|
215
|
+
patch_path
|
216
|
+
end
|
107
217
|
|
108
218
|
def bake_new_file_patch
|
109
219
|
patch_path = File.join(@gems_dir, 'new_file.patch')
|
@@ -241,6 +351,24 @@ class TestGemPatch < Gem::TestCase
|
|
241
351
|
end
|
242
352
|
EOF
|
243
353
|
end
|
354
|
+
|
355
|
+
def change_file_with_fuzz_patch
|
356
|
+
<<-EOF
|
357
|
+
diff -u a/lib/foo.rb b/lib/foo.rb
|
358
|
+
--- a/lib/foo.rb
|
359
|
+
+++ b/lib/foo.rb
|
360
|
+
@@ -1,6 +1,8 @@
|
361
|
+
module FooBar
|
362
|
+
- def bar
|
363
|
+
- 'Original'
|
364
|
+
+ class Bar
|
365
|
+
+ def foo_bar
|
366
|
+
+ 'Patched'
|
367
|
+
+ end
|
368
|
+
end
|
369
|
+
end
|
370
|
+
EOF
|
371
|
+
end
|
244
372
|
|
245
373
|
def new_file_patch
|
246
374
|
<<-EOF
|
metadata
CHANGED
@@ -1,59 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem-patch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Josef Stribny
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-04-22 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
|
-
description:
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
gem.\n"
|
13
|
+
description: |2
|
14
|
+
`gem-patch` is a RubyGems plugin that helps to patch gems without manually opening and rebuilding them.
|
15
|
+
It opens a given .gem file, extracts it, patches it with system `patch` command,
|
16
|
+
clones its spec, updates the file list and builds the patched gem.
|
19
17
|
email: jstribny@redhat.com
|
20
18
|
executables: []
|
21
19
|
extensions: []
|
22
20
|
extra_rdoc_files: []
|
23
21
|
files:
|
24
22
|
- README.md
|
25
|
-
- README.rdoc
|
26
23
|
- LICENCE
|
27
24
|
- rakefile.rb
|
28
|
-
- lib/
|
25
|
+
- lib/rubygems/commands/patch_command.rb
|
29
26
|
- lib/rubygems/package-1.8.rb
|
30
27
|
- lib/rubygems/patcher.rb
|
31
|
-
- lib/
|
32
|
-
- test/rubygems/test_gem_patch.rb
|
28
|
+
- lib/rubygems_plugin.rb
|
33
29
|
- test/rubygems/test_gem_commands_patch_command.rb
|
30
|
+
- test/rubygems/test_gem_patch.rb
|
34
31
|
homepage: http://github.com/strzibny/gem-patch
|
35
32
|
licenses:
|
36
33
|
- MIT
|
34
|
+
metadata: {}
|
37
35
|
post_install_message:
|
38
36
|
rdoc_options: []
|
39
37
|
require_paths:
|
40
38
|
- lib
|
41
39
|
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
40
|
requirements:
|
44
|
-
- -
|
41
|
+
- - '>='
|
45
42
|
- !ruby/object:Gem::Version
|
46
43
|
version: 1.8.7
|
47
44
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
-
none: false
|
49
45
|
requirements:
|
50
|
-
- -
|
46
|
+
- - '>='
|
51
47
|
- !ruby/object:Gem::Version
|
52
48
|
version: 1.8.0
|
53
49
|
requirements: []
|
54
50
|
rubyforge_project:
|
55
|
-
rubygems_version:
|
51
|
+
rubygems_version: 2.0.3
|
56
52
|
signing_key:
|
57
|
-
specification_version:
|
53
|
+
specification_version: 4
|
58
54
|
summary: RubyGems plugin for patching gems.
|
59
55
|
test_files: []
|
data/README.rdoc
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
= gem-patch
|
2
|
-
|
3
|
-
A RubyGems plugin that patches gems.
|
4
|
-
|
5
|
-
== Description
|
6
|
-
|
7
|
-
`gem-patch` is a RubyGems plugin that helps to patch gems without manually opening and rebuilding them. It opens a given .gem file, extracts it, patches it with system `patch` command, clones its spec, updates the file list and builds the patched gem.
|
8
|
-
|
9
|
-
== Installation
|
10
|
-
|
11
|
-
Run:
|
12
|
-
`gem install gem-patch`
|
13
|
-
|
14
|
-
== Usage
|
15
|
-
|
16
|
-
`gem patch [options] name-version.gem PATCH [PATCH ...]`
|
17
|
-
|
18
|
-
Options:
|
19
|
-
|
20
|
-
`-pNUMBER` or `--strip=NUMBER` sets the file name strip count to NUMBER (same options as for `patch` command on Linux machines).
|
21
|
-
`--verbose` prints additional info and STDOUT from `patch` command
|
22
|
-
|
23
|
-
== Requirements
|
24
|
-
|
25
|
-
This version is build for RubyGems 2.0.a, a branch for RubyGems 1.8 is also available.
|