AGWA / git-crypt

Transparent file encryption in git
https://www.agwa.name/projects/git-crypt/
GNU General Public License v3.0
8.33k stars 479 forks source link

git-crypt and submodules #42

Closed ghost closed 9 years ago

ghost commented 9 years ago

It looks like git-crypt does not behave well when there are submodules. Maybe there is a way to prevent this problem by adding some lines in .gitattributes but here is a way to reproduce the problem:

~$ git --version
git version 2.1.4

~$ git-crypt --version
git-crypt 0.4.2

~$ mkdir repo_wsm

~$ cd repo_wsm/

~/repo_wsm$ git init
Initialized empty Git repository in /home/ggueguen/tmp/repo_wsm/.git/

~/repo_wsm$ git-crypt init
Generating key...

~/repo_wsm$ cat - << EOF > .gitattributes
> * filter=git-crypt diff=git-crypt
> .gitattributes !filter !diff
> EOF

~/repo_wsm$ git-crypt status
not encrypted: .gitattributes

~/repo_wsm$ git submodule add https://github.com/AGWA/git-crypt.git
Cloning into 'git-crypt'...
remote: Counting objects: 618, done.
remote: Total 618 (delta 0), reused 0 (delta 0), pack-reused 618
Receiving objects: 100% (618/618), 207.50 KiB | 0 bytes/s, done.
Resolving deltas: 100% (389/389), done.
Checking connectivity... done.

~/repo_wsm$ git-crypt status
not encrypted: .gitattributes
    encrypted: .gitmodules
fatal: git cat-file ede1461563709498d397d8230d233c3d9a25880e: bad file
git-crypt: Error: 'git cat-file' failed - is this a Git repository?
ghost commented 9 years ago

Adding each folder containing a submodule to .gitattributes with !filter !diff solves the problem but it would be easier if git-crypt could ignore submodules by default.

AGWA commented 9 years ago

Thanks for reporting this. I've pushed a fix. git-crypt status now ignores non-files in the tree.

Another issue when using git-crypt to encrypt an entire repository that includes sub-modules is making sure that the .gitmodules file isn't encrypted. git-crypt can't prevent this; you have to put a .gitmodules !filter !diff entry in .gitattributes yourself. I added a note to the README about this.