summaryrefslogtreecommitdiffstats
path: root/content/posts/WIP-freecad-and-git/index.org
blob: 78478579dbeb246672755506ad0d5a5587e20d9e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#+TITLE: Freecad and Git
#+DATE: 2021-03-23T01:23:58-04:00
#+DRAFT: true
#+DESCRIPTION:
#+TAGS[]:
#+KEYWORDS[]:
#+SLUG:
#+SUMMARY:

I've been working a lot with [[https://freecadweb.org/][FreeCAD]] recently since I got my 3D
printer, and have run into some issues.

Between the MacOS version and Linux version of FreeCAD (both 0.19,
maybe different builds?), a project that I've been working on for a
couple days has become broken to the point where I can no longer
edit the sketches, rendering it useless.

This has led me on a quest to find out how I can manage these files
through version control like =git=.

It would seem that FreeCAD saves are nothing more than zip files
containing text documents, which should make this rather easy.

Unfortunately there isn't a standard process to git control a
zipped folder, though I have come across a couple methods which
when used together, result in an adequate solution.

The main component of this workaround is a great little script
called [[https://bitbucket.org/sippey/zippey/src/master/][zippey]], which allows git to handle and diff zip files in a
way that makes storing them much more efficient.

The second isn't as much a tool as it is a snippet from a [[https://tante.cc/2010/06/23/managing-zip-based-file-formats-in-git/][blog post]]
about diffing zip files with git. By combining both these methods
we can arrive at a pretty good method of handling FreeCAD save
data.

The first step is to download the zippy python program. Since I
keep all source repositories under =~/src= in directories based on
the website and user who created them, I'll be cloning it to
=~/src/bitbucket.org/sippey/zippey=.

Then I configure my =~/.gitconfig= to so that the =diff= and
=filter= settings are how I want them.

I'll also setup a global git [[https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes][attributes]] file so that I don't need
to set the association with =.FCStd= files in each repo individually.

I add the following lines to my =~/.gitconfig=.

#+begin_src conf
[diff "zip"]
textconv = unzip -c -a
[core]
    attributesfile = ~/.gitattributes
[filter "zippey"]
    smudge = /home/dante/src/bitbucket.org/sippey/zippey/zippey.py d
    clean = /home/dante/src/bitbucket.org/sippey/zippey/zippey.py e
#+end_src

Then I create a =~/.gitattributes= file with the following content.

#+begin_src conf
,*.FCStd filter=zippey
,*.FCStd diff=zip
#+end_src

With this =git= should be now be able to effectively diff and store
proper deltas when FreeCAD files are modified.

Keep in mind you need to redo this process on each computer you
plan on using this with, otherwise the files git produces won't
make any sense.

Also despite having diffs, these files cannot be merged or rebased,
the use of diffs is just do that =git= can store the file more efficiently.