0

Found this issue yesterday when needing to restore a versioned CoreData model from git and it didn't work. XCode only saw it as an XML file and would never allow me to change it to a CoreData Model.

It seems that when storing to Git the xcdatamodel and xcdatamodeld files are being converted to folders with xml files inside called contents.

I posted about the issue in the iOS Community on Twitter and was told that I needed to create a .gitattributes file with the line

*.xcdatamodel binary merge=union

I did that and have tried everything I can think of to get this to store the xcdatamodel correctly and nothing is changing.

I have done:

mv .git/index .git/index.bak
git reset
git status
git add .
git commit
git push

I have tried modifying the CoreData model in XCode so it notices a change and then pushing to git again, and closing XCode and deleting the xcdatamodeld pushing to git and then putting it back and pushing as if it's a new file.

No matter what I've tried I still see the xcdatamodeld as a folder with xcdatamodel folders inside it and inside them, xml contents files.

What am I doing wrong?

kittonian
  • 1,020
  • 10
  • 22
  • That’s what the `xcdatamodel` and `xcdatamodeld` are supposed to be. They’re not files, they’re folders. The model is supposed to be in `contents`. – Tom Harrington Oct 06 '22 at 16:20
  • OK, but you cannot download a folder from git, only files. So are you saying that in order to restore an xcdatamodel version manually I would need to download the contents and then create a folder with the correct filename.xcdatamodel and it will work? – kittonian Oct 06 '22 at 17:22
  • We use a private Gitea server and the web interface doesn't seem to allow me to download a folder, only a file. I can download the entire branch or the entire repository but I don't get an option to download a folder, only a file. – kittonian Oct 06 '22 at 19:51
  • It's hard to tell what's going wrong here. What you describe is how Core Data models work. Normally they just work in git, no special steps are required, because they're just folders and XML files, which git has no trouble with. – Tom Harrington Oct 06 '22 at 21:54
  • Git stores files, but the file names come with forward slashes, e.g., `xcdatamodel/contents`. Git will *create*, in your working tree, a folder `xcdatamodel/` to hold `contents` if there's a *file* named `xcdatamodel/contents` in the commit. So normally you don't need to care about this particular distinction. The places you *do* need to care occur with case folding (which is on a per-component basis in your OS, which stores folder-and-file instead of full-path) and when trying to store an empty folder (which Git can't do). – torek Oct 07 '22 at 00:40
  • That said, `*.xcdatamodel binary merge=union` is not really right. It will avoid merge conflicts, but won't merge XML files correctly. Git *cannot* merge XML files correctly. Allow merge conflicts and fix the result yourself, or do not store XML files in Git (your choice). – torek Oct 07 '22 at 00:42
  • @torek The file name is not `xcdatamodel/contents`. It’s a directory named `xcdatamodel` that contains a file named `contents. There are no slashes in Core Data file names. – Tom Harrington Oct 07 '22 at 02:37
  • 1. Do you you think we've maybe looked into this already? 2. Don't be demeaning. I am well aware of how to use git from the command line. That wasn't the point of this post. If you have something useful to contribute please do so, otherwise.... – kittonian Oct 07 '22 at 14:31
  • @TomHarrington: as far as *Git* is concerned, the file *is* named `xcdatamodel/contents`. There *are no directories* in Git. Directories exist in your working tree, but not in Git's index, and Git builds commits from Git's index. Use `git ls-files --stage` to see. – torek Oct 07 '22 at 16:45
  • The initial question had to do specifically with XCode's xcdatamodel files and how git is storing them. Apparently it's not an issue as there doesn't seem to be anything special about the folder itself. Just name it accordingly and put the contents xml file inside and it'll work just fine. That's really what I needed to know. – kittonian Oct 07 '22 at 18:19

0 Answers0