cocoapods-patch 0.0.7 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2626728359e198af7ecc119c2bc846520c233f725cea13857a12a936bfacb527
4
- data.tar.gz: ef94a39a36598ce2274b099f34af86953a21086d52b135dff893f6e21cf5aebf
3
+ metadata.gz: 9f8a1091ce7f95d367d0fb5cdcdc01533bade7aa87c3750c03607ca0d0d6893b
4
+ data.tar.gz: 91ad3babdd2763618a7bedc0bb4186d63558df08c6bbc2a72453e4dcc2fbe555
5
5
  SHA512:
6
- metadata.gz: 230e132b95a6bcadeb9e442fa5576ec5b57c36cefc543fae0feed769569fbadf4ac0e0f8e7799939e938a3bdede73d15517e150a3e6daf042471d2321fc9584b
7
- data.tar.gz: d335a0613d53c0931caacd4e2938e8083d7b32cdbb843dd406b91e5714a77e8b678537577fa8d05cef2d2f2a4accfc39a80f210db17f074f3d22012d82e4b5a8
6
+ metadata.gz: 56c086ce0f18238fedb169377d9de115cf50a660d2d5356b78c9c973441fe79e30f98372fcce72242431afcbbe418ae95aaaa23f5986ba9bdbdf551f8a8843ba
7
+ data.tar.gz: 29cafa7c713700b5ff74a3c82ade35f20885d8411ee9a117be870e473ee60a8d4c58f377c0506ab9e2b4ef382734b1768c4318d65c930000008357178221749d
data/CHANGELOG.md ADDED
@@ -0,0 +1,39 @@
1
+ # Installation & Update
2
+
3
+ To install or update cocoapods-patch see [README](https://github.com/DoubleSymmetry/cocoapods-patch).
4
+
5
+ ## Master
6
+
7
+ ##### Enhancements
8
+
9
+ * None.
10
+
11
+ ##### Bug Fixes
12
+
13
+ * None.
14
+
15
+ ## 1.0.1 (2.11.21)
16
+
17
+ ##### Enhancements
18
+
19
+ * Change name of generated patch files to include pod version used
20
+ [dcvz](https://github.com/dcvz)
21
+
22
+ * Use lockfile to use more correct installation of fresh dependencies.
23
+ [dcvz](https://github.com/dcvz)
24
+
25
+ ##### Bug Fixes
26
+
27
+ * None.
28
+
29
+ ## 1.0.0 (1.11.21)
30
+
31
+ ##### Enhancements
32
+
33
+ * Use official pre_integrate hook
34
+ [dcvz](https://github.com/dcvz)
35
+ [#7](https://github.com/DoubleSymmetry/cocoapods-patch/pull/7)
36
+
37
+ ##### Bug Fixes
38
+
39
+ * None.
data/README.md ADDED
@@ -0,0 +1,48 @@
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
+ **NOTE:**
19
+ `cocoapods-patch` version 1.0.0 and above require you to use Cocoapods 1.11.0 or greater.
20
+ For anything below that please use version 0.0.9.
21
+
22
+ ## Migrating to v1.0.1+
23
+
24
+ In v1.0.1 of the plugin we've changed the naming scheme of the generated patch files to also include the version of the pods used to generate the patches. This will allow us to do more automation safety and make sure patches are applied successfully.
25
+
26
+ We've added a new command to help with the migration. After updating before doing a `pod install` please first run `pod patch migrate` which will translate any existing patches into their new format. This will use the current version of the pods stated in your lockfile.
27
+
28
+ ## Usage
29
+
30
+ ### Creating a patch
31
+
32
+ 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:
33
+
34
+ pod patch create POD_NAME
35
+
36
+ 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.
37
+
38
+ ### Automatically applying all patches on install
39
+
40
+ 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.
41
+
42
+ ### Applying a patch manually
43
+
44
+ When you want to apply a patch to a pod, run
45
+
46
+ pod patch apply POD_NAME
47
+
48
+ 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.7"
2
+ VERSION = "1.0.1"
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'
@@ -37,16 +37,16 @@ def apply_patch(patch_file)
37
37
  directory_arg = (ios_project_path.to_s.eql? ".") ? "Pods" : File.join(ios_project_path, 'Pods')
38
38
 
39
39
  Dir.chdir(repo_root) {
40
- check_cmd = "git apply --check #{patch_file} --directory=#{directory_arg} -p2 2> /dev/null"
40
+ check_cmd = "git apply --check '#{patch_file}' --directory='#{directory_arg}' -p2 2> /dev/null"
41
41
 
42
42
  can_apply = system(check_cmd)
43
43
  if can_apply
44
44
  apply_cmd = check_cmd.gsub('--check ', '')
45
45
  did_apply = system(apply_cmd)
46
46
  if did_apply
47
- Pod::UI.puts "Successfully applied #{patch_file}"
47
+ Pod::UI.puts "Successfully applied #{patch_file} 🎉"
48
48
  else
49
- Pod::UI.warn "Failed to apply #{patch_file}"
49
+ Pod::UI.warn "Error: failed to apply #{patch_file}"
50
50
  end
51
51
  end
52
52
  }
@@ -24,28 +24,53 @@ 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
28
- FileUtils.mkdir_p('patches')
34
+ # create patches folder if it doesn't exist
35
+ FileUtils.mkdir_p(patches_path)
36
+
29
37
  Dir.mktmpdir('cocoapods-patch-', config.project_root) do |work_dir|
30
38
  sandbox = Pod::Sandbox.new(work_dir)
31
- installer = Pod::Installer.new(sandbox, config.podfile)
39
+ installer = Pod::Installer.new(sandbox, config.podfile, config.lockfile)
32
40
  installer.clean_install = true
33
41
 
34
42
  installer.prepare
35
43
  installer.resolve_dependencies
36
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
+
37
55
  pod_installer = installer.send :create_pod_installer, @name
38
56
  pod_installer.install!
39
57
 
58
+ UI.puts "Creating patch"
40
59
  theirs = Pathname.new(work_dir).join(@name).relative_path_from(config.project_root)
41
60
  ours = config.project_pods_root.join(@name).relative_path_from(config.project_root)
42
- gen_diff_cmd = "git diff --no-index #{theirs} #{ours} > #{patch_file}"
61
+ gen_diff_cmd = "git diff --no-index '#{theirs}' '#{ours}' > '#{patch_file}'"
43
62
 
44
63
  did_succeed = system(gen_diff_cmd)
45
64
  if not did_succeed.nil?
46
- 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
47
72
  else
48
- UI.warn "Error creating patch for #{@name}"
73
+ UI.warn "Error: failed to create patch for #{@name}"
49
74
  end
50
75
  end
51
76
  end
@@ -0,0 +1,44 @@
1
+ require 'pathname'
2
+
3
+ module Pod
4
+ class Command
5
+ class Patch < Command
6
+ class Migrate < Patch
7
+ self.description = <<-DESC
8
+ Migrates previous patch files to the new format.
9
+ DESC
10
+
11
+ def clear_patches_folder_if_empty
12
+ if Dir.empty?(patches_path)
13
+ FileUtils.remove_dir(patches_path)
14
+ end
15
+ end
16
+
17
+ def run
18
+ UI.puts 'Migrating patches...'
19
+ patches_dir = Pathname.new(Dir.pwd) + 'patches'
20
+ if patches_dir.directory?
21
+ patches = patches_dir.each_child.select { |c| c.to_s.end_with?('.diff') }
22
+ patches.each do |p|
23
+ # check if patch file has new format
24
+ if p.to_s.include?('+')
25
+ # do nothing
26
+ else
27
+ # rename patch file
28
+ pod_name = p.basename('.diff').to_s
29
+ UI.puts "Renaming #{pod_name}"
30
+
31
+ pod_version = config.lockfile.version(pod_name)
32
+ new_patch_name = p.to_s.gsub('.diff', "+#{pod_version}.diff")
33
+
34
+ File.rename(p, new_patch_name)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+
@@ -0,0 +1,20 @@
1
+ require_relative 'patch/apply'
2
+ require_relative 'patch/create'
3
+
4
+ module Pod
5
+ class Command
6
+ class Patch < Command
7
+ self.abstract_command = true
8
+ self.summary = 'Create & apply patches to Pods.'
9
+
10
+ def patch_file
11
+ version = config.lockfile.version(@name)
12
+ return config.project_root + 'patches' + "#{@name}+#{version}.diff"
13
+ end
14
+
15
+ def patches_path
16
+ config.project_root + 'patches'
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ require_relative 'command/patch'
2
+ require_relative 'command/patch/apply'
3
+ require_relative 'command/patch/create'
4
+ require_relative 'command/patch/migrate'
data/lib/pod/hook.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'cocoapods'
2
+ require 'pathname'
3
+ require_relative 'command/patch/apply'
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
+
19
+ Pod::HooksManager.register('cocoapods-patch', :pre_integrate) do |context|
20
+ Pod::UI.puts 'Applying patches if necessary'
21
+ patches_dir = Pathname.new(Dir.pwd) + 'patches'
22
+ if patches_dir.directory?
23
+ patches = patches_dir.each_child.select { |c| c.to_s.end_with?('.diff') }
24
+ patches.each do |p|
25
+ pod_name = File.basename(p, ".diff")
26
+ # check if patch is in new format otherwise warn user
27
+ unless p.to_s.include?('+')
28
+ Pod::UI.puts "WARNING: #{pod_name}.diff has an old naming format. Please run pod patch migration first before pod install. See the README for more information.".yellow
29
+ end
30
+
31
+ apply_patch(p)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,43 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Double Symmetry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-23 00:00:00.000000000 Z
11
+ date: 2021-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cocoapods
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.11.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.11.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '1.3'
33
+ version: '2.0'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '1.3'
40
+ version: '2.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ">="
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
47
+ version: '13.0'
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: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
39
67
  - !ruby/object:Gem::Version
40
- version: '0'
68
+ version: '3.9'
41
69
  description: Create & apply patches to Pods
42
70
  email:
43
71
  - dev@doublesymmetry.com
@@ -45,14 +73,16 @@ 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
+ - CHANGELOG.md
77
+ - README.md
78
+ - lib/cocoapods_patch.rb
55
79
  - lib/cocoapods_plugin.rb
80
+ - lib/pod/command.rb
81
+ - lib/pod/command/patch.rb
82
+ - lib/pod/command/patch/apply.rb
83
+ - lib/pod/command/patch/create.rb
84
+ - lib/pod/command/patch/migrate.rb
85
+ - lib/pod/hook.rb
56
86
  homepage: https://github.com/DoubleSymmetry/cocoapods-patch
57
87
  licenses:
58
88
  - MIT
@@ -1,12 +0,0 @@
1
- module Pod
2
- class Command
3
- class Patch < Command
4
- self.abstract_command = true
5
- self.summary = 'Create & apply patches to Pods.'
6
-
7
- def patch_file
8
- config.project_root + 'patches' + "#{@name}.diff"
9
- end
10
- end
11
- end
12
- end
@@ -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,27 +0,0 @@
1
- require 'cocoapods'
2
- require 'pathname'
3
- require_relative 'command/patch/apply'
4
-
5
- class Pod::Installer
6
- # Because our patches may also delete files, we need to apply them before the pod project is generated
7
- # The project is generated in the `integrate` method, so we override it
8
- # We first run our patch action and then the original implementation of the method
9
- # Reference: https://github.com/CocoaPods/CocoaPods/blob/760828a07f8fcfbff03bce13f56a1789b6f5a95d/lib/cocoapods/installer.rb#L178
10
- alias_method :integrate_old, :integrate
11
-
12
- def integrate
13
- # apply our patches
14
- apply_patches
15
- # run the original implementation
16
- integrate_old
17
- end
18
-
19
- def apply_patches
20
- Pod::UI.puts 'Applying patches if necessary'
21
- patches_dir = Pathname.new(Dir.pwd) + 'patches'
22
- if patches_dir.directory?
23
- patches = patches_dir.each_child.select { |c| c.to_s.end_with?('.diff') }
24
- patches.each { |p| apply_patch(p) }
25
- end
26
- end
27
- end
@@ -1 +0,0 @@
1
- require 'cocoapods-patch/gem_version'