elasticdog / transcrypt

transparently encrypt files within a git repository
MIT License
1.44k stars 102 forks source link

New cmd to add file to crypt list (.gitattributes) #125

Open soraxas opened 2 years ago

soraxas commented 2 years ago

This PR adds a convenient command that quickly adds file/patterns to .gitattribute. The command is available as git alias too (similar to git ls-crypt)

The command also checks if the given file/pattern already exists in the file, and it will be a no-op if the line already exists.

$ cat .gitattributes
#pattern  filter=crypt diff=crypt merge=crypt
$ git add-crypt foobar
$ cat .gitattributes
#pattern  filter=crypt diff=crypt merge=crypt
foobar  filter=crypt diff=crypt merge=crypt
$ git add-crypt 'configs/*.json'
$ cat .gitattributes
#pattern  filter=crypt diff=crypt merge=crypt
foobar  filter=crypt diff=crypt merge=crypt
configs/*.json  filter=crypt diff=crypt merge=crypt
$ git add-crypt 'foobar'
$ git add-crypt 'foobar'
$ git add-crypt 'foobar'
$ cat .gitattributes
#pattern  filter=crypt diff=crypt merge=crypt
foobar  filter=crypt diff=crypt merge=crypt
configs/*.json  filter=crypt diff=crypt merge=crypt
jmurty commented 2 years ago

Hi @soraxas this looks like a great feature!

Thanks also for cleaning up the git-common-dir vs git-dir logic. I have pushed some minor changes to get shellcheck and shfmt linting checks to pass.

@elasticdog What do you think of this approach and transcrypt add / git add-crypt command names?