29

I am working on a project using cocoapods and suddenly I see myself doing some changes in one of the libraries. How can I ensure that those changes will never be override by a pod update? Is there any way to introduce changes in a pod without updating the github project?

UPDATE : Forking a project

I have tried to fork the project and create a new specfile to point to the new project. I was able to install the basic stuff, however, for some reason, there are some dependencies that are installed but can't be referenced inside the pods project. Currently I have this in my podsfile:

'WhirlyGlobe', :podspec => 'https://raw.github.com/tiagoalmeida/WhirlyGlobe/master/WhirlyGlobe.podspec'

The fork of the library is in https://github.com/tiagoalmeida/WhirlyGlobe

UPDATE2: Missing Headers

I have found that the headers (Pods/Headers) for boost and Eigen (used from the WhrilyGlobe) are not being generated.

UPDATE3: Trying to do Something about the headers

I have tried to look in some of the configurations that are in this thread and I have tried the solutions in the FAQ but I believe that my problem is different. The headers are actually missing.

UPDATE4: Attacking the cocoapods version

I have uninstalled cocoapods and installed the version 0.20.2 (that was working before trying to use my fork) and it keeps all the same :/.

Community
  • 1
  • 1
Tiago Almeida
  • 14,081
  • 3
  • 67
  • 82
  • 3
    one another way create subclass of the library class that you want to change. – user1548843 Jul 04 '13 at 11:59
  • 2
    you could fork the repository, and change the pod to point to your fork – wattson12 Jul 04 '13 at 12:00
  • @wattson12 Thanks for your suggestion. How can I change the pod to point to my fork without creating a new pod (and poluting the cocoapods repository)? – Tiago Almeida Jul 04 '13 at 13:35
  • you just provide a url in the podfile, added detail in an answer – wattson12 Jul 04 '13 at 14:40
  • What version of CocoaPods are you using? – MishieMoo Jul 05 '13 at 17:11
  • I have run gem query to check the version, although I have two numbers in that gem... cocoapods (0.22.1, 0.20.2), cocoapods-core (0.22.1, 0.20.2), cocoapods-downloader (0.1.1). I am going to reinstall cocoapods and try again. – Tiago Almeida Jul 08 '13 at 09:04
  • i got a question: so what's the point of jumping through all these cocoapod hoops? why not just copy/paste the contents of the cocoapod files and integrate it into your own iOS project? – abbood Mar 28 '14 at 06:20
  • @abbood For two reasons: Coherence (all external libs using the same approach) and to use the power of cocoapods. I can still update the lib in my fork (and I have more control on the updates) and still do pod update :). – Tiago Almeida Mar 28 '14 at 12:15

6 Answers6

10

@pgb and wattson provided me good information but ultimately the problem was in a combination of things.

I don't know why but it seems that cocoapods 0.22 handles headers differently. I uninstalled cocoapods and installed the version 0.20.2.

To check the version of cocoapods I have used gem query and I have removed the cocoapods with gem uninstall cocoapods and installed the cocoapods with gem install cocoapods --version 0.20.2.

I have used my podfile like this:

'WhirlyGlobe', :podspec => 'https://raw.github.com/tiagoalmeida/WhirlyGlobe/master/WhirlyGlobe.podspec'

Where podspec points to my new podspec. I made like this because I need to remove the :tag from the original podfile (otherwise it always points to the same spot) and this way I have more control over the file.

In the podspec I have changed the source:

s.source = { :git => "https://github.com/tiagoalmeida/WhirlyGlobe.git"} 

To point into my fork and removed the tag.

Thanks @pgb and @wattson for the attempts to help me. Upvoted both because they were both usefull.

Tiago Almeida
  • 14,081
  • 3
  • 67
  • 82
6

You can fork a repository and then add your forked repo as a pod, so say you've forked the repo to https://github.com/tiago/ThePodProject.git, then set the pod to:

pod 'ThePodProject', :git => 'https://github.com/tiago/ThePodProject.git'

see here for more detail (under "From a podspec in the root of a library repo")

wattson12
  • 11,176
  • 2
  • 32
  • 34
  • 1
    The repository I am trying to change is the WhirlyGlobe repository. It happens that WhirlyGlobe doesn't have a spec file. Therefore, after some research I have changed my podfile to the following: `pod 'WhirlyGlobe', :podspec => 'https://raw.github.com/tiagoalmeida/WhirlyGlobe/master/WhirlyGlobe.podspec'`. However, now my project can't find the library (althought it is included in the pod) and I can't import anything... – Tiago Almeida Jul 04 '13 at 15:25
  • have you run pod update? (maybe delete the Podfile.lock first) – wattson12 Jul 04 '13 at 16:22
  • I did. And Also updated cocoapods because I had some problems untill I reached that podspec thing. This messed up all my configuration. Now even inside the pod project it cant find dependencies :/. – Tiago Almeida Jul 04 '13 at 16:28
  • it seems like there might be something related to this pod, i tried installing from your podspec but it seems to be taking a long time to download. edit: but thats because the repo is massive, i'll let it run and see what happens – wattson12 Jul 04 '13 at 16:31
  • the install failed for me: Unable to locate the executable `hg`. is there any dependencies this pod requires? – wattson12 Jul 04 '13 at 16:40
  • not that I am aware of. I had this all working out before I tried to fork and use my specfile. The only thing I changed in the specfile was the git repository and removed the tag on that git repository. I can create the workspace project but the Pod project has build errors (can't find some files that are also in the pod project). – Tiago Almeida Jul 04 '13 at 16:43
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/32900/discussion-between-tiago-almeida-and-wattson12) – Tiago Almeida Jul 04 '13 at 16:45
1

You are close to having it working with your forked repository.

I just tried it with the following Podfile:

pod 'WhirlyGlobe', :git => 'https://github.com/tiagoalmeida/WhirlyGlobe'

It downloaded WhirlyGlobe and then failed because hg was missing. I simply installed it using Homebrew: brew install mercurial and then runnning pod install was able to install all the dependencies.

The project compiles, but I'm not sure it works, go ahead and try it.

Be aware that it took a really long time to download and compile all the dependencies (shapelib in particular).

pgb
  • 24,813
  • 12
  • 83
  • 113
  • I have edited my podfile to be just like yours. I still get the same problem! The headers from boost library and Eigen are not created in the folder Pods/Headers. Therefore, the WhrilyGlobe (the one that uses those libraries) can't find them. This is such an odd problem :/ – Tiago Almeida Jul 05 '13 at 08:40
0

Just want to add my few cent to the answer. I encounter the same problem. As someone suggested above too I went to subclass-ing the pod lib. I was using ACEDrawingView and it has property image which is readonly. I subclass-ed it and made this property read/write. I personal feel going by sub-class is more elegant and hassle free solution to this kind of problem. Unless there is huge development you want to do on side of your main project.

Alok C
  • 2,787
  • 3
  • 25
  • 44
0

Saving custom changes using only Git (no forking)

For those looking for a simple solution, I have successfully solved this problem by using git stashes.

As mentioned, pod update will overwrite any changes you made. However, if you're using git what I like to do is commit all my changes except for my pod changes.

Once the only changes I have on my branch are the Pods changes, I stash those changes by running git stash save "Custom Cocoapod changes, apply after every pod update". You can give it any message you'd like by changing the text between the "".

This command has the side effect of reseting your working directory to the previous HEAD, so if you want to reapply those stashes you can just run git stash apply to get those changes back in, and then you can commit them to save them.

Don't use git stash pop as this will delete the stash after applying it.

Now, at some undetermined time in the future, when you update your pods and its time to apply the stash again, what you're going to want to do is run git stash list. this will return a list of all the stashes you've made with the most recent being zero indexed. You'll probably see something like this:

stash@{0}: On featureFooBar: foo bar
stash@{1}: On Master: Custom Cocoapod changes, apply after every pod update
...

If the custom cocoa pods changes stash is in stash@{0} then perfect, you can just run a git stash apply again and you'll get those changes on your working directory. Otherwise once you find which stash number your pods changes are you can apply that stash by running git stash apply stash@{1}

Applying stashes is easiest when you have a clean working directory on the same branch but thats not required. This page gives a good description of git stash and how to use it otherwise.

This is not the most full proof solution since I can foresee some issues when you have multiple people on the same project, but it's a simple way to solve this without resorting to more involved solutions.

Community
  • 1
  • 1
gadu
  • 1,816
  • 1
  • 17
  • 31
0

There is an another way exist where you can fork the repository , modify the changes and maintain the library through cocoapods for future bug fixes and feature enhancement ..... enter image description here

I have recently published tutorial for the same here https://medium.com/@mihirpmehta/how-to-modify-cocoapods-library-within-pods-647d2bf7e1cb

Mihir Mehta
  • 13,743
  • 3
  • 64
  • 88