tags:

views:

212

answers:

3

If I add files to my project, and my co-worker adds files to his project, and we both check our files in, should we expect to have conflicts? What's the best way to handle this?

+1  A: 

Yes, this is common.

I usually just resolve the conflicts by hand in a text editor; the project format isn't actually that hard to read. If the changes are small (just adding or removing a few files) you could just reappy the change through the Xcode UI if you prefer.

Stephen Canon
A: 

Yes there will be conflicts. The best way to fix this is to open the .prxproj in a text editor like TextMate, and search for the lines with >>>. Just remove the svn merge stuff (the lines with arrows and the line telling you which branch it came from). Then save the file and mark it as resolved. You're done!

Steven Canfield
Just removing the merge markers doesn't mean you get a correct merge. There's more to resolving conflicts than removing the markers.
Sander Rijken
Seems to me that this whole process could have been designed a little better, but thanks for confirming that it wasn't!
morgancodes
Normally you would be correct. However in my experience, 99% of all merge conflicts in the project.pbxproj file are in fact fixed just fine by removing the merge markers - after all, you are adding files, someone else is adding files, so you want both sides of the merge.
Kendall Helmstetter Gelner
Well, it will work in the special case where you and your colleague both add files to the project, and neither of you removes anything or changes any build settings or does almost *anything else at all*, but god help you if you do try any of those things.
Stephen Canon
Build settings almost never change after initial setup, or at best infrequently - so there's really never a conflict with that. I am telling you what happens in real life with over a year working on iPhone projects with several other developers at a time, that pretty much every merge conflict is two people adding files to a project at the same time. Yes there are some things that COULD go wrong, but in practice it does not happen. Two people adding files is not the special case, it's the great majority of cases. Almost any other change you make is easily automerged on update.
Kendall Helmstetter Gelner
As an addendum, what you should not try to resolve is merge issues in xib files - that almost always goes badly. Figure out who has the smallest change and just make them re-do it. Better still, try to make sure only one person is working on a xib at a time.
Kendall Helmstetter Gelner
Yes I wrote my post from the perspective Kendall describes: a year of working on iPhone projects using svn. It's nearly always just adding files. If someone is changing build settings they communicate that explicitly to the team anyway.
Steven Canfield
A: 

This happens often enough to me that I have a shell script to fix these things - almost all the time merge conflicts are just because you and another person have both added new files to the project, and so you just want to keep both sides of the merge. Run this script in the main project directory (where the build and Classes directory is) any time you have a merge conflict, go to XCode to make sure it can load the merged project before you commit the fixed merge!

Note that I use this with git, you may want to check whatever merge conflict markers there are in your code use the characters below to show sections in conflict (==== is the middle divider).

mergeproj.sh

#!/bin/sh

projectfile=`find -d . -name 'project.pbxproj'`
projectdir=`echo *.xcodeproj`
projectfile="${projectdir}/project.pbxproj"
tempfile="${projectdir}/project.pbxproj.out"
savefile="${projectdir}/project.pbxproj.mergesave"

cat $projectfile | grep -v "<<<<<<< HEAD" | grep -v "=======" | grep -v "^>>>>>>> " > $tempfile
cp $projectfile $savefile
mv $tempfile $projectfile

Kendall Helmstetter Gelner