Skip to content

Commit a52f602

Browse files
author
Chaitanya Gupta
committed
Add README.
1 parent 77ce8b9 commit a52f602

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
Introduction
2+
------------
3+
4+
This project aims to make it easy to see differences in different
5+
versions (e.g. `git diff`) of .xcdatamodel files used to describe Core
6+
Data managed object models. An example `git diff` output follows:
7+
8+
diff --git a/Recipes.xcdatamodel/elements b/Recipes.xcdatamodel/elements
9+
index 35a20f3..939bc61 100644
10+
--- a/Recipes.xcdatamodel/elements
11+
+++ b/Recipes.xcdatamodel/elements
12+
@@ -2,8 +2,8 @@ Entity: Image (NSManagedObject)
13+
Att: image Transformable O dafQGIhBFATAxE1hyQd5z5cpRg0OLP4+M+W3+xhA6jU=
14+
Rel: recipe Recipe image Nullify I fVH2lmmkHE4j/FvzfJ2et3KsNxcA8p5BJp2d/xd4hH0=
15+
16+
-Entity: Ingredient (Ingredient) 5tCLlA1r9p1UWdOTr3XJ+ZzBr6bxraWAs3Vt9zCAZek=
17+
- Att: amount String O b9/jjR2iJtm4oldVJwj25X+/hpEL6/1CM5hLhgV48Iw=
18+
+Entity: Ingredient (Ingredient) 7nbTTDaWG1lAddHYHum4xP4IA/N90NYv9GLkGK+sueQ=
19+
+ Att: amount Integer16 O RmH9Sk61kxsb8+GUEqlEkIuV4tDjxxhMNsHUu/tBW6I=
20+
Att: displayOrder Integer16 kMPJ+qU+fnBipO5Ajep+KT3rKB9zeOPrav0q4rMSt7k=
21+
Att: name String jLmWXAAxrGiROYTzEQlBrZZTlb6f2bF9575UvHrUaJA=
22+
Rel: recipe Recipe ingredients Nullify O I GvmjTsOh76OGkr0Lmnxdh8u6FO4E+iuEYa0mRZPuKJQ=
23+
24+
The project contains a script, `print_xcdatamodel`, which prints a
25+
textual representation of a .xcdatamodel file. This script as the
26+
textconv program for a diff driver in git (see Installation below).
27+
28+
`print_xcdatamodel` works by compiling the xcdatamodel file to a mom
29+
file using the `momc` compiler. The compiled mom file is then read by
30+
another program, `MOMPrinter`, which also ships with this
31+
project. `MOMPrinter` takes a .mom file as input and prints a detailed
32+
description of the data model on standard output.
33+
34+
Installation
35+
------------
36+
37+
1. Copy `print_xcdatamodel` to your $PATH
38+
39+
2. Build MOMPrinter and copy the binary to your path
40+
41+
* Open the MOMPrinter project in Xcode and build with release
42+
configuration
43+
* Right click on Products > MOMPrinter in the project navigator,
44+
then click 'Show in Finder' to locate the binary
45+
* Copy the binary to your $PATH
46+
47+
Alternatively, you can build the project on the command line using
48+
xcodebuild.
49+
50+
3. Ensure that `momc` is available in your $PATH. For Xcode 4.3.2, the
51+
`momc` binary can be found at
52+
/Applications/Xcode.app/Contents/Developer/usr/bin/momc
53+
54+
4. Set up `git diff` to use `print_xcdatamodel` for xcdatamodel files
55+
56+
* Add the following line to your projects `.gitattributes` file
57+
(if you want this to apply globally, you can use
58+
`~/.gitattributes`)
59+
60+
elements diff=xcdatamodel
61+
62+
This tells to use `xcdatamodel` as the diff driver for
63+
.xcdatamodel/elements files (which contain your model's entire
64+
definition). What exactly is this `xcdatamodel` driver? That is
65+
defined in the next section.
66+
67+
* We can set up the `xcdatamodel` driver using `git config`. Use
68+
these commands to set up the driver (use the `--global` option
69+
if you want to set up the driver for all your projects)
70+
71+
git config diff.xcdatamodel.xcfuncname ^Entity
72+
git config diff.xcdatamodel.textconv print_xcdatamodel
73+
74+
Now, whenever you use any git command which shows a diff output
75+
(e.g. `git diff`, `git log -p`, `git show`, etc.) and there's a change
76+
in an xcdatamodel file, you should be able to understand easily what
77+
changes have been made to the data model.

0 commit comments

Comments
 (0)