cocoapods-patch 0.0.4 → 0.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9894b0de3c7d124458215a8f93fb28437b98fdaad904eac8019e90a97fa2263
4
- data.tar.gz: 4f0e69e6cfb98e6de924a1399d6f75720063be8e148796c00bcf61b2fe222222
3
+ metadata.gz: f0aa117625e0803e3576bbb68fcbb3b005794e874324c83f215be1ab88e995cd
4
+ data.tar.gz: 9a8b0648a734914a667805591fcc2d005ab797ba76efe76f8d8d86709299a1d5
5
5
  SHA512:
6
- metadata.gz: 26fe03a6d87d55716158439f59dc213aede0bf6bf49b76d03d2b8556e9815d889314abc072435c1aa026189bc888f0f8ff4331fb03d6b3549b92f64b03ae905c
7
- data.tar.gz: e404b677a854b965b1951206ff0dd466de15b3b52fdca78691e89fb83ffed67ea6c5534867d6b1e6fc791bb1bc123aac47f96b691ce72a6b2d0e316ca8d75726
6
+ metadata.gz: 793bafd2255d2e9d86881fdc6087e6cdd75d4d73cc36364a53cac6914bbfa8befc0735503542ff9e8c55aba4fbd223c28ef029af3172c56785bb115c31176415
7
+ data.tar.gz: b0bc3602df6ca681dfdb14da70e4a05e3d2d5d311ab08b0c14b3df4e01c9d000b881e6c8acfb5272bf0353745855242ff21bcc8c6ebefa88fa38075237c234f1
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+
2
+ # cocoapods-patch
3
+
4
+ cocoapods-patch is a Cocoapods plugin that solves the problem of forking and maintaining a separate version of a Pod when only a small (often a one-liner), long-lived change in the original Pod is needed.
5
+
6
+ The idea behind the plugin is that patches should live inside the repo (in the `patches` directory) and be distributed together with the rest of your source code. This way, you can more easily code review and test the changes to a Pod and keep it synced across your team.
7
+
8
+ ## Installation
9
+
10
+ First, install the plugin
11
+
12
+ $ gem install cocoapods-patch
13
+
14
+ Next, add a `plugin 'cocoapods-patch'` line to your Podfile to use the plugin. This will enable [automatic apply](#automatically-applying-all-patches-on-install) so you don't have to worry about it again.
15
+
16
+ That's it, you're done.
17
+
18
+ ## Usage
19
+
20
+ ### Creating a patch
21
+
22
+ To create a patch, first, you need to modify the source code of the installed Pod. Do the desired changes to the Pod source code (under the `Pods/` directory). Once you're satisfied with the result, run:
23
+
24
+ pod patch create POD_NAME
25
+
26
+ This will create a `patches/POD_NAME.diff` file in your repository. The patch is a diff between the Pod version you have specified in your Podfile and your local changes to the Pod. You can now add and commit this patch.
27
+
28
+ ### Automatically applying all patches on install
29
+
30
+ cocoapod-patch can be seamlessly integrated into the normal iOS development workflow. If you follow the installation instructions and add `plugin 'cocoapods-patch'` to your Podfile, every time you do a `pod install`, the plugin will go throught all the available patches and try to apply them. It will only warn you when the patch cannot be applied.
31
+
32
+ ### Applying a patch manually
33
+
34
+ When you want to apply a patch to a pod, run
35
+
36
+ pod patch apply POD_NAME
37
+
38
+ This command will look for the appropriate patch in the `patches` directory and, if possibly, apply it to your local Pod. A patch can be applied only once.
@@ -1,3 +1,3 @@
1
1
  module CocoapodsPatch
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -1,2 +1,2 @@
1
- require 'cocoapods-patch/command'
2
- require 'cocoapods-patch/hook'
1
+ require 'pod/command'
2
+ require 'pod/hook'
@@ -0,0 +1,3 @@
1
+ require_relative 'command/patch'
2
+ require_relative 'command/patch/apply'
3
+ require_relative 'command/patch/create'
@@ -1,3 +1,6 @@
1
+ require_relative 'patch/apply'
2
+ require_relative 'patch/create'
3
+
1
4
  module Pod
2
5
  class Command
3
6
  class Patch < Command
@@ -7,6 +10,10 @@ module Pod
7
10
  def patch_file
8
11
  config.project_root + 'patches' + "#{@name}.diff"
9
12
  end
13
+
14
+ def patches_path
15
+ config.project_root + 'patches'
16
+ end
10
17
  end
11
18
  end
12
19
  end
@@ -0,0 +1,53 @@
1
+ require 'cocoapods'
2
+
3
+ module Pod
4
+ class Command
5
+ class Patch < Command
6
+ class Apply < Patch
7
+ self.summary = 'Applies a patch to an installed Pod'
8
+
9
+ self.arguments = [
10
+ CLAide::Argument.new('NAME', true)
11
+ ]
12
+
13
+ def initialize(argv)
14
+ @name = argv.shift_argument
15
+ super
16
+ end
17
+
18
+ def validate!
19
+ super
20
+ help! 'A Pod name is required.' unless @name
21
+ end
22
+
23
+ def run
24
+ apply_patch patch_file
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ # also used from the post-install hook
32
+ def apply_patch(patch_file)
33
+ working_dir = Dir.pwd
34
+ repo_root = `git rev-parse --show-toplevel`.strip
35
+ ios_project_path = Pathname.new(working_dir).relative_path_from(Pathname.new(repo_root))
36
+
37
+ directory_arg = (ios_project_path.to_s.eql? ".") ? "Pods" : File.join(ios_project_path, 'Pods')
38
+
39
+ Dir.chdir(repo_root) {
40
+ check_cmd = "git apply --check '#{patch_file}' --directory='#{directory_arg}' -p2 2> /dev/null"
41
+
42
+ can_apply = system(check_cmd)
43
+ if can_apply
44
+ apply_cmd = check_cmd.gsub('--check ', '')
45
+ did_apply = system(apply_cmd)
46
+ if did_apply
47
+ Pod::UI.puts "Successfully applied #{patch_file} 🎉"
48
+ else
49
+ Pod::UI.warn "Error: failed to apply #{patch_file}"
50
+ end
51
+ end
52
+ }
53
+ end
@@ -24,7 +24,16 @@ module Pod
24
24
  help! 'A Pod name is required.' unless @name
25
25
  end
26
26
 
27
+ def clear_patches_folder_if_empty
28
+ if Dir.empty?(patches_path)
29
+ FileUtils.remove_dir(patches_path)
30
+ end
31
+ end
32
+
27
33
  def run
34
+ # create patches folder if it doesn't exist
35
+ FileUtils.mkdir_p(patches_path)
36
+
28
37
  Dir.mktmpdir('cocoapods-patch-', config.project_root) do |work_dir|
29
38
  sandbox = Pod::Sandbox.new(work_dir)
30
39
  installer = Pod::Installer.new(sandbox, config.podfile)
@@ -33,18 +42,35 @@ module Pod
33
42
  installer.prepare
34
43
  installer.resolve_dependencies
35
44
 
45
+ UI.puts "Checking if pod exists in project..."
46
+ specs_by_platform = installer.send :specs_for_pod, @name
47
+
48
+ if specs_by_platform.empty?
49
+ clear_patches_folder_if_empty
50
+ help! "Given pod does not exist in project. Did you use incorrect pod name?"
51
+
52
+ return
53
+ end
54
+
36
55
  pod_installer = installer.send :create_pod_installer, @name
37
56
  pod_installer.install!
38
57
 
58
+ UI.puts "Creating patch"
39
59
  theirs = Pathname.new(work_dir).join(@name).relative_path_from(config.project_root)
40
60
  ours = config.project_pods_root.join(@name).relative_path_from(config.project_root)
41
- gen_diff_cmd = "git diff --no-index #{theirs} #{ours} > #{patch_file}"
61
+ gen_diff_cmd = "git diff --no-index '#{theirs}' '#{ours}' > '#{patch_file}'"
42
62
 
43
63
  did_succeed = system(gen_diff_cmd)
44
64
  if not did_succeed.nil?
45
- UI.puts "Created patch #{patch_file}"
65
+ if File.empty?(patch_file)
66
+ File.delete(patch_file)
67
+ clear_patches_folder_if_empty
68
+ UI.warn "Error: no changes detected between current pod and original"
69
+ else
70
+ UI.puts "Created patch #{patch_file} 🎉"
71
+ end
46
72
  else
47
- UI.warn "Error creating patch for #{@name}"
73
+ UI.warn "Error: failed to create patch for #{@name}"
48
74
  end
49
75
  end
50
76
  end
@@ -2,6 +2,22 @@ require 'cocoapods'
2
2
  require 'pathname'
3
3
  require_relative 'command/patch/apply'
4
4
 
5
+ module CocoapodsPatch
6
+ module Hooks
7
+ Pod::HooksManager.register('cocoapods-patch', :pre_install) do |context|
8
+ Pod::UI.puts 'Preparing patchable pods for clean patching'
9
+ patches_dir = Pathname.new(Dir.pwd) + 'patches'
10
+ if patches_dir.directory?
11
+ patches = patches_dir.each_child.select { |c| c.to_s.end_with?('.diff') }
12
+ patches.each do |p|
13
+ pod_name = File.basename(p, ".diff")
14
+ context.sandbox.clean_pod(pod_name)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
5
21
  class Pod::Installer
6
22
  # Because our patches may also delete files, we need to apply them before the pod project is generated
7
23
  # The project is generated in the `integrate` method, so we override it
@@ -19,7 +35,9 @@ class Pod::Installer
19
35
  def apply_patches
20
36
  Pod::UI.puts 'Applying patches if necessary'
21
37
  patches_dir = Pathname.new(Dir.pwd) + 'patches'
22
- patches = patches_dir.each_child.select { |c| c.to_s.end_with?('.diff') }
23
- patches.each { |p| apply_patch(p) }
38
+ if patches_dir.directory?
39
+ patches = patches_dir.each_child.select { |c| c.to_s.end_with?('.diff') }
40
+ patches.each { |p| apply_patch(p) }
41
+ end
24
42
  end
25
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Double Symmetry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-09 00:00:00.000000000 Z
11
+ date: 2021-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
47
+ version: '3.9'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ">="
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cocoapods
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
39
67
  - !ruby/object:Gem::Version
40
- version: '0'
68
+ version: '1.0'
41
69
  description: Create & apply patches to Pods
42
70
  email:
43
71
  - dev@doublesymmetry.com
@@ -45,14 +73,14 @@ executables: []
45
73
  extensions: []
46
74
  extra_rdoc_files: []
47
75
  files:
48
- - lib/cocoapods-patch.rb
49
- - lib/cocoapods-patch/command.rb
50
- - lib/cocoapods-patch/command/patch.rb
51
- - lib/cocoapods-patch/command/patch/apply.rb
52
- - lib/cocoapods-patch/command/patch/create.rb
53
- - lib/cocoapods-patch/gem_version.rb
54
- - lib/cocoapods-patch/hook.rb
76
+ - README.md
77
+ - lib/cocoapods_patch.rb
55
78
  - lib/cocoapods_plugin.rb
79
+ - lib/pod/command.rb
80
+ - lib/pod/command/patch.rb
81
+ - lib/pod/command/patch/apply.rb
82
+ - lib/pod/command/patch/create.rb
83
+ - lib/pod/hook.rb
56
84
  homepage: https://github.com/DoubleSymmetry/cocoapods-patch
57
85
  licenses:
58
86
  - MIT
@@ -1 +0,0 @@
1
- require 'cocoapods-patch/gem_version'
@@ -1,3 +0,0 @@
1
- require 'cocoapods-patch/command/patch'
2
- require 'cocoapods-patch/command/patch/apply'
3
- require 'cocoapods-patch/command/patch/create'
@@ -1,44 +0,0 @@
1
- require 'cocoapods'
2
-
3
- module Pod
4
- class Command
5
- class Patch < Command
6
- class Apply < Patch
7
- self.summary = 'Applies a patch to an installed Pod'
8
-
9
- self.arguments = [
10
- CLAide::Argument.new('NAME', true)
11
- ]
12
-
13
- def initialize(argv)
14
- @name = argv.shift_argument
15
- super
16
- end
17
-
18
- def validate!
19
- super
20
- help! 'A Pod name is required.' unless @name
21
- end
22
-
23
- def run
24
- apply_patch patch_file
25
- end
26
- end
27
- end
28
- end
29
- end
30
-
31
- # also used from the post-install hook
32
- def apply_patch(patch_file)
33
- check_cmd = "git apply --check #{patch_file} --directory=Pods -p2 2> /dev/null"
34
- can_apply = system(check_cmd)
35
- if can_apply
36
- apply_cmd = check_cmd.gsub('--check ', '')
37
- did_apply = system(apply_cmd)
38
- if did_apply
39
- Pod::UI.puts "Successfully applied #{patch_file}"
40
- else
41
- Pod::UI.warn "Failed to apply #{patch_file}"
42
- end
43
- end
44
- end