Can the LibreOffice / OpenOffice merge tool be used as `git-mergetool`?

3.1k views Asked by At

I stumbled upon an old blog post suggesting this, unfortunately only as an unimplemented idea. Has this been done meanwhile / how can it be achieved? (I heard TortoiseGit might do this, but I'm running Linux)

An alternative could also be the re-zip approach mentioned here, suggesting a git filter which tracks the uncompressed OpenDocuments and recompresses them on checkout, which would offer the option to at least merge (and diff) the xml contents instead of binary garbage (or the lossy odt2txt), however I didn't find any updates on this approach either, the last post about this warns about potential flaws in this approach.

2

There are 2 answers

0
Tobias Kienzler On BEST ANSWER

Inspired by twalberg's comment I wrote to simple scripts od2fod and fod2od which use the --convert-to parameter of Libre/OpenOffice in order to convert the zipped xml into an uncompressed one and vice versa. Due to a bug denying CLI actions when the LibreOffice GUI is running I had to write the workaround loInstance:

#!/bin/bash
tmpdir=$(mktemp -d)
cp -rf ~/.libreoffice $tmpdir
soffice -env:UserInstallation=file://$tmpdir $@
rm -rf $tmpdir

od2fod and fod2od are simple, though:

#!/bin/bash
loInstance --headless --convert-to f${1#*.} $1

and

#!/bin/bash
loInstance --headless --convert-to ${1#*.f} $1

One could now setup a clean and smudge filter in .gitattributes, however I notice LO keeps track of superfluous meta-data which brakes the clean-smudge circle. So for now this can only be used as a imperfect textconv tool for git-diff...

1
Vince On

You can try it, and you will let us know. From what I remember, merge tools are configured to have 4 inputs, so you will have to configure Git to use it as a merge tool.

You have to add a couple lines in the config file, merge.tool, mergetool.<tool>.path and mergetool.<tool>.cmd

http://www.kernel.org/pub/software/scm/git/docs/git-config.html (search for "merge.tool" in the page)

http://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html

Hope it helps