elasticdog / transcrypt

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

Fix incorrect salt when partially staged files are commited #119

Closed Aramgutang closed 3 years ago

Aramgutang commented 3 years ago

See ticket #118.

jmurty commented 3 years ago

@Aramgutang Can you think of any way we could add unit test coverage for partial commits of encrypted files?

Since git-p refuses to work with transcrypt-encrypted files it might be tough to simulate the behaviour.

Aramgutang commented 3 years ago

Yeah, I read through the git add/apply/am documentation, and couldn't find anything useable. Basically the scenario to reproduce requires invoking the clean filter for a file, while feeding it input that isn't actually the contents of the file, all within the context of generating a blob object for the change.

The various GUIs probably have their own implementations of this, which is why some seem to be able to handle staging partial changes on encrypted files, and some aren't.

Aramgutang commented 3 years ago

I read through the code for git-cola, and it appears that the way it stages hunks/lines is by generating patch files, writing them to a tmpfile, and passing them to git apply:

https://github.com/git-cola/git-cola/blob/b65aced9c089183eb008cd8c276b3c1941ee1f87/cola/diffparse.py#L261 https://github.com/git-cola/git-cola/blob/ac7e533541b46f7de5e778132be11227639ba0a7/cola/cmds.py#L287

But then again, staging partial changes to encrypted files in git-cola doesn't actually work, and it's probably because git apply doesn't pass the content through the filters, and neither does git-cola before writing the patchfile (which was the code I was hoping to find).

I reckon the only viable way to approach it would be along the lines of:

Seems like a lot of work...

jmurty commented 3 years ago

Whew, yeah, definitely a lot of work. For this one, knowing that the change hasn’t broken anything already tested (most features) is probably good enough.

Thanks for the explanation @Aramgutang

jmurty commented 3 years ago

Thanks for this fix @Aramgutang!

I tested it manually with VSCode pre- and post-fix and found the behaviour exactly as you described.

It's weird that VSCode allows partial commits when other tools refuse to, but that's a pretty important Git "client" to work with.