Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with git merge #140

Open
tobiasBora opened this issue Jan 27, 2018 · 5 comments
Open

Problem with git merge #140

tobiasBora opened this issue Jan 27, 2018 · 5 comments

Comments

@tobiasBora
Copy link

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: 7a23105

Thank you!

@tobiasBora
Copy link
Author

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?

@tobiasBora
Copy link
Author

tobiasBora commented Jan 28, 2018

I created a pull request, it should work now on any new git-crypt repository #141

@themoritz
Copy link

Thanks for the workaround @tobiasBora, it works perfectly.

@tobiasBora
Copy link
Author

tobiasBora commented Jan 31, 2018

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 : #141
Just, this PR does not correct the repo that has already been initialized.

@fullofcaffeine
Copy link

+1 thanks for this @tobiasBora, works great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants