Skip to content

Patches to the Pods can be sometimes applied multiple timesΒ #150

@gentlee

Description

@gentlee

Probably when you remove and reinstall node_modules but don't remove Pods, patches are applied multiple times.

Here is the fixed script that checks if patch was already applied:

require 'cocoapods'


module Pod
    class Patch
        def find_patches
            return Dir["ios/patches/*.diff"]
        end
        
        def apply_patch(file)
            repo_root = `git rev-parse --show-toplevel`.strip
            directory_arg = Dir.glob(Pathname(repo_root).join("**/**/Pods")).first.sub("#{repo_root}/", "")
            puts "HEY #{file}"
        
            Dir.chdir(repo_root) {
                check_reverse_cmd = "git apply --check --reverse '#{file}' --directory='#{directory_arg}' -p2 2> /dev/null"
                can_reverse = system(check_reverse_cmd)
                if can_reverse
                    Pod::UI.puts "Patch #{file} already applied, skipping"
                else
                    check_cmd = check_reverse_cmd.gsub('--reverse ', '')
                    can_apply = system(check_cmd)
                    if can_apply
                        apply_cmd = check_cmd.gsub('--check ', '')
                        did_apply = system(apply_cmd)
                        if did_apply
                            Pod::UI.puts "Successfully applied #{file} πŸŽ‰"
                        else
                            Pod::UI.warn "Error: failed to apply #{file}"
                        end
                    end
                end
            }
        end

        def apply
            files = find_patches()
            files.each do |f|
                apply_patch("#{Dir.pwd}/#{f}")
            end
        end
    end
end

p = Pod::Patch.new
p.apply

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions