Improve the merge driver script to fix a problem that could occur
with complex merges where an encrypted file that couldn't be merged
cleanly would cause the entire merge to fail with the message:
error: Your local changes to the following files would be overwritten by merge:
sensitive_file
The bug was caused by being too aggressive in overwriting the working-
copy file $5 with merged content. Doing this early and in all cases
could leave what looks like manually modified files in the working
copy that Git would notice part-way through a multi-step merge and
abort.
The fix is to overwrite the working-copy $5 file only when a merge
is successful (no conflicts) at which point we really need that
specific $5 filename to contain the merged data to encrypt it.
In all other cases, we now leave the working-copy $5 file untouched
and only modify the temporary file $2 which is the file Git expects
to be managed by merge driver scripts.
Other minor improvements in this change are:
quote ALL uses of $x file name/path arguments to guard against
failures due to spaces in file paths
simplify if/then logic to exit fast when needed
try to better explain in comments what on earth is happening in
the merge driver script and why.
Hi @elasticdog I hit a problem with my merge driver script addition today in real-world usage, and this is the fix. I'll merge this straight to master unless you see any problems?
Improve the merge driver script to fix a problem that could occur with complex merges where an encrypted file that couldn't be merged cleanly would cause the entire merge to fail with the message:
The bug was caused by being too aggressive in overwriting the working- copy file $5 with merged content. Doing this early and in all cases could leave what looks like manually modified files in the working copy that Git would notice part-way through a multi-step merge and abort.
The fix is to overwrite the working-copy $5 file only when a merge is successful (no conflicts) at which point we really need that specific $5 filename to contain the merged data to encrypt it. In all other cases, we now leave the working-copy $5 file untouched and only modify the temporary file $2 which is the file Git expects to be managed by merge driver scripts.
Other minor improvements in this change are: