As a human doing both Computer Aided Design (CAD) and some software development, I feel like I always wanted to use Git for version control.

I’ve been working with FreeCAD a lot lately and it seems as the file format is just a renamed .zip. I know that OnShape does a good job at this yet sometimes cloud software can’t be an option and open-source stuff is just great. The goal here is to try using some kind of commit hooks to unzip/zip and leverage Git diffs.

First attempt with zippey

I discovered this Git filter simple example from 2014 that focuses on (un)zipping .docx files which are apparently using the same compression system.

I created a simple GitForFreeCAD repo, containing:

.gitattributes
zippey.py
BeltA.FCStd

with the first two copied over from the repo, with just a small edit for the .gitattributes file:

*.FCStd filter=zippey

And then running the repo config commands to use this filter

git config filter.zippey.required true
git config filter.zippey.smudge "$PWD/.zippey/zippey.py d"
git config filter.zippey.clean "$PWD/.zippey/zippey.py e"

After making opening the file and making a slight change, we can see the real text-based diff in action!

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/37297725-03a4-4b08-a085-bffd3a747f38/2B93C7EB-4ECF-4BCB-987E-90802B84125D.jpeg

Cloning on a new machine

Note: [zippey.py](<http://zippey.py>) isn’t part of the repo anymore, it’s to be installed globally at ~/.zippey/zippey.py

# Install zippey
curl -fLo $HOME/.zippey/zippey.py --create-dirs <https://raw.githubusercontent.com/pierremtb/GitForFreeCAD/master/zippey.py>
chmod +x $HOME/.zippey/zippey.py
# Clone without checking out (the folder will look empty)
git clone --no-checkout <https://github.com/pierremtb/GeeXY>
cd GeeXY
# Setup the filter
git config filter.zippey.required true
git config filter.zippey.smudge "$HOME/.zippey/zippey.py d"
git config filter.zippey.clean "$HOME/.zippey/zippey.py e"
# Finally checkout, which will call the .clean function
git checkout --

How does it work?

This hack is pretty smart: git actually detects the binary diffs while you work with the CAD software, so you can see that changes are made on the Source Control of say VS Code, or by running git status.

And when staging the files for commit (eg. git add BeltA.FCStd), the scripts run and “smudges” the binary file into a git-readable text file.

When checking out a repo (eg. git pull), the text files are being “cleaned” back into their FreeCAD-compatible binary format.

Next steps