-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from elasticdog/69-fix-merge-of-encrypted-file…
…s-with-conflicts Fix `transcrypt`'s handling of merges where encrypted files have conflicting changes, a situation which would lead to Git producing "merged" files with conflict markers around partially- or fully-encrypted content that cannot be sensibly merged by a person. See issue #69 and a bunch of related issues. The root problem is that git does not run the `smudge`/`textconv` filter on all BASE, LOCAL, REMOTE conflicting version files before attempting a three-way merge. This change adds: - a merge driver script to pre-decrypt conflicting BASE, LOCAL, and REMOTE file versions then run git's internal `merge-file` command to merge the decrypted versions - git repo settings to configure the merge driver - recommendation to add the extra `merge=crypt` setting to *.gitattribute* definitions - tests of merge functionality to prove that non-conflicting and conflicting merges work. Also included are minor listing and formatting fixes from applying the recommended tools to do this clean-up, and documentation for how to run these tools in *README.md* The bulk of this work is originally from https://github.com/ixc/transcrypt/commits/fix-merge-with-conflicts
- Loading branch information
Showing
6 changed files
with
152 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,14 +92,14 @@ using the command line options. Run `transcrypt --help` for more details. | |
### Designate a File to be Encrypted | ||
|
||
Once a repository has been configured with transcrypt, you can designate for | ||
files to be encrypted by applying the "crypt" filter and diff to a | ||
files to be encrypted by applying the "crypt" filter, diff, and merge to a | ||
[pattern](https://www.kernel.org/pub/software/scm/git/docs/gitignore.html#_pattern_format) | ||
in the top-level _[.gitattributes](http://git-scm.com/docs/gitattributes)_ | ||
config. If that pattern matches a file in your repository, the file will be | ||
transparently encrypted once you stage and commit it: | ||
|
||
$ cd <path-to-your-repo>/ | ||
$ echo 'sensitive_file filter=crypt diff=crypt' >> .gitattributes | ||
$ echo 'sensitive_file filter=crypt diff=crypt merge=crypt' >> .gitattributes | ||
$ git add .gitattributes sensitive_file | ||
$ git commit -m 'Add encrypted version of a sensitive file' | ||
|
||
|
@@ -297,11 +297,22 @@ Copyright © 2014-2020, [Aaron Bull Schaefer](mailto:[email protected]). | |
|
||
## Contributing | ||
|
||
### Linting and formatting | ||
|
||
Please use: | ||
|
||
- the [shellcheck](https://www.shellcheck.net) tool to check for subtle bash | ||
scripting errors in the _transcrypt_ file, and apply the recommendations when | ||
possible. E.g: `shellcheck transcrypt` | ||
- the [shfmt](https://github.com/mvdan/sh) tool to apply consistent formatting | ||
to the _transcrypt_ file, e.g: `shfmt -w transcrypt` | ||
- the [Prettier](https://prettier.io) tool to apply consistent formatting to the | ||
_README.md_ file, e.g: `prettier --write README.md` | ||
|
||
### Tests | ||
|
||
Tests are written using [bats-core](https://github.com/bats-core/bats-core) | ||
version of "Bash Automated Testing System" and stored in the *tests/* | ||
directory. | ||
version of "Bash Automated Testing System" and stored in the _tests/_ directory. | ||
|
||
To run the tests: | ||
|
||
|
@@ -311,6 +322,15 @@ To run the tests: | |
|
||
## Changes | ||
|
||
Fixes: | ||
|
||
- Fix handling of branch merges with conflicts in encrypted files, which would | ||
previously leave the user to manually merge files with a mix of encrypted and | ||
unencrypted content. | ||
|
||
To apply this fix in projects that already use transcrypt: uninstall and | ||
re-init transcrypt, then add `merge=crypt` to the patterns in _.gitattributes_ | ||
|
||
Improvements: | ||
|
||
- Add Git pre-commit hook to reject commit of file that should be encrypted but | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/usr/bin/env bats | ||
|
||
load $BATS_TEST_DIRNAME/_test_helper.bash | ||
|
||
@test "merge: branches with encrypted file - addition, no conflict" { | ||
echo "1. First step" > sensitive_file | ||
encrypt_named_file sensitive_file | ||
|
||
git checkout -b branch-2 | ||
echo "2. Second step" >> sensitive_file | ||
git add sensitive_file | ||
git commit -m "Add line 2" | ||
|
||
git checkout - | ||
git merge branch-2 | ||
|
||
run cat sensitive_file | ||
[ "$status" -eq 0 ] | ||
[ "${lines[0]}" = "1. First step" ] | ||
[ "${lines[1]}" = "2. Second step" ] | ||
} | ||
|
||
@test "merge: branches with encrypted file - line change, no conflict" { | ||
echo "1. First step" > sensitive_file | ||
encrypt_named_file sensitive_file | ||
|
||
git checkout -b branch-2 | ||
echo "1. Step the first" > sensitive_file # Cause line conflict | ||
echo "2. Second step" >> sensitive_file | ||
git add sensitive_file | ||
git commit -m "Add line 2, change line 1" | ||
|
||
git checkout - | ||
git merge branch-2 | ||
|
||
run cat sensitive_file | ||
[ "$status" -eq 0 ] | ||
[ "${lines[0]}" = "1. Step the first" ] | ||
[ "${lines[1]}" = "2. Second step" ] | ||
} | ||
|
||
@test "merge: branches with encrypted file - with conflicts" { | ||
echo "1. First step" > sensitive_file | ||
encrypt_named_file sensitive_file | ||
|
||
git checkout -b branch-2 | ||
echo "1. Step the first" > sensitive_file # Cause line conflict | ||
echo "2. Second step" >> sensitive_file | ||
git add sensitive_file | ||
git commit -m "Add line 2, change line 1" | ||
|
||
git checkout - | ||
echo "a. First step" > sensitive_file | ||
git add sensitive_file | ||
git commit -m "Change line 1 in original branch to set up conflict" | ||
|
||
run git merge branch-2 | ||
[ "$status" -ne 0 ] | ||
[ "${lines[1]}" = "CONFLICT (content): Merge conflict in sensitive_file" ] | ||
|
||
run cat sensitive_file | ||
[ "$status" -eq 0 ] | ||
[ "${lines[0]}" = "<<<<<<< master" ] | ||
[ "${lines[1]}" = "a. First step" ] | ||
[ "${lines[2]}" = "=======" ] | ||
[ "${lines[3]}" = "1. Step the first" ] | ||
[ "${lines[4]}" = "2. Second step" ] | ||
[ "${lines[5]}" = ">>>>>>> branch-2" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters