git-crypt
git-crypt copied to clipboard
Problem with git merge
Hello,
Thank you for this great tool. I don't know why, but I can't merge two branches that are supported by git-crypt... If I tried, the conflicted files are not changed at all, and I can't find any <<<<<< HEAD
inside.
I'm using git-crypt 0.6.0, from debian unstable repository. Maybe it's related to this PR: https://github.com/AGWA/git-crypt/pull/107/commits/7a231050232eda53ca63aa6cc124113ae6ff8270
Thank you!
Ok, so i found a quick workaround that should be easy to implement (and it seems to even work with git mergetools
):
First in the file .git/config
, add at the end containing:
[merge "git-crypt"]
name = A custom merge driver used to merge git-crypted files.
driver = ./my-merge-tool.sh %O %A %B
recursive = binary
and at the root of the repository, create a file my-merge-tool.sh
:
#!/usr/bin/env bash
ancestor_decrypted="$1__decrypt"
current_decrypted="$2__decrypt"
other_decrypted="$3__decrypt"
echo ""
echo "###########################"
echo "# Git crypt driver called #"
echo "###########################"
echo ""
echo "Decrypting ancestor file..."
cat $1 | git-crypt smudge > "${ancestor_decrypted}"
echo "Decrypting current file..."
cat $2 | git-crypt smudge > "${current_decrypted}"
echo "Decrypting other file..."
cat $3 | git-crypt smudge > "${other_decrypted}"
echo ""
echo "Merging ..."
git merge-file -L "current branch" -L "ancestor branch" -L "other branch" "${current_decrypted}" "${ancestor_decrypted}" "${other_decrypted}"
exit_code=$?
cat "${current_decrypted}" | git-crypt clean > $2
echo "Removing temporary files..."
rm "${other_decrypted}" "${ancestor_decrypted}" "${current_decrypted}"
if [ "$exit_code" -eq "0" ]
then
echo "@@@ No conflict!"
else
echo "@@@ You need to solve some conflicts..."
fi
exit $exit_code
Then make sure it's executable:
chmod +x my-merge-tool.sh
and modify your .gitattributes
to add a merge option, with something like:
crypt/** filter=git-crypt diff=git-crypt merge=git-crypt
That's all, you can now merge, and even use "mergetool"!
NB: you can of course put any folder for my-merge-tool.sh
, like in the .git-crypt/
folder, you just need to be consistent.
Would it be possible to include this in the git-crypt
tool so that by default the configuration is the good one?
I created a pull request, it should work now on any new git-crypt repository https://github.com/AGWA/git-crypt/pull/141
Thanks for the workaround @tobiasBora, it works perfectly.
No problem. And this workaround also corrects the cherry-pick problem. By the way I put a wrong link for the PR above, this one is better : https://github.com/AGWA/git-crypt/pull/141 Just, this PR does not correct the repo that has already been initialized.
+1 thanks for this @tobiasBora, works great!