elasticdog / transcrypt

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

Creating a second context on pre-release branch creates duplicate pre-commit file #165

Closed Sceosasciba closed 1 year ago

Sceosasciba commented 1 year ago

I've been using the pre-release branch (transcrypt v2.3.0-pre) to be able to play around with the contexts, as it was exactly what I needed for a project.

When creating a context it creates the pre-commit file, in the .git/hooks folder. When creating a second context you get a warning that the pre-commit file already existed, so it created the file pre-commit-crypt in the same folder. But it needs to be installed. The weird thing is that this looks like a complete duplicate of the pre-commit file, but if I don't give this new file executable rights it doesn't actually encrypt the files for the second context.

When creating a third context it either overwrites the pre-commit-crypt file or doesn't, but I immediately gave it the right permissions and it did still encrypt both the second and third context.

Since it looks like a duplicate it should probably just be able to use that first pre-commit file? This would make using multiple contexts easier.

Unrelated to this, but related to contexts. I have not yet found a way to decrypt files that are part of contexts when cloning the repo in a separate place. Would probably need a context parameter in the transcrypt decrypt function. But kind of assuming since it's pre-release this just wasn't added yet.

jmurty commented 1 year ago

Hi @Sceosasciba thanks for the feedback on the upcoming contexts feature.

The warning when re-installing the pre-commit file was an oversight. I think I have fixed this bug on the master branch in commit c06331fc55944e1c2b0eb34398c06ead9833a5ee

However you can largely ignore the pre-commit file: the pre-commit hook is only a safety check for Git client tools that aren't compatible with transcrypt, the hook doesn't do any work to encrypt or decrypt files. Contexts should work fine, regardless of the mistaken warning.

To decrypt files in different contexts in a cloned repository, you must re-initialise transcrypt again for each extra context by including the --context / -C option in the init command. For example if you have a "super" context in the original repository, you can display the init command for that context like this: transcrypt --display --context super. Run the init command given by the prior command in the cloned repo to decrypt files in the "super" context. The "super" context init command will also include an option with the context name, and will look something like this: transcrypt -C super -c aes-256-cbc -p 'password'

The --display option gives a hint about extra contexts, when present, by listing them with in a line like this:
The repository has 2 contexts: default super

Sceosasciba commented 1 year ago

Hey, thanks for the fast commit! This has resolved the issue. And your explanation helped, although it was more of a problem of me needing to read more carefully. But got the decrypting of cloned repo's working too now, thanks again!