I was in search of a new merge tool to use on macOS today, and decided to roll with the free p4merge tool, since it’s pretty solid and slightly less long in the tooth than my old friend, kdiff3. But a quick search on how to use it as the default UI merge tool for jj didn’t reveal any immediate answers on the right way to copy-pasta my way to success, so I had to do just a tiny bit of digging.
The wrong way
The half-right-half-wrong AI Answers said that it should be as simple as a new entry in my ~/.config/jj/config.toml file, like this:
# NOTE: This is the WRONG config, see below for the one that worked for me.
[merge-tools.p4merge]
program = "p4merge"
program-args = ["$left", "$right", "$base", "$output"]
But no, that didn’t work. There’s a few things wrong with it. First and most obvious, program-args isn’t correct, it’s merge-args. And second, the order of the inputs is wrong. It should be base, left, right, output.
Second, and more interesting, p4merge was not in my path. So I popped in /Applications/p4merge.app, where it’s actually located. But that binary does not accept command line arguments. Instead, there’s actually a shim inside of the application bundle that does, and forwards them to the GUI application. That’s located at /Applications/p4merge.app/Contents/Resources/launchp4merge. A helpful KB article on the Perforce site tells us that we need our own shim to execute this shim, which I dutifully set up. And it worked!
But I got to thinking, “Why do I need an intermediary bash script just to forward arguments to this other executable?” I tried it without the intermediary script, just telling jj to go straight for /Applications/p4merge.app/Contents/Resources/launchp4merge, and it worked too, woohoo!
The right way
The final jj setup in my config.toml file looks like this:
[merge-tools.p4merge]
program = "/Applications/p4merge.app/Contents/Resources/launchp4merge"
merge-args = [
"$base",
"$left",
"$right",
"$output"
]
Now I can run jj resolve whenever I have conflicts, and it’ll open up p4merge for each conflicting file in the stack. Super handy!
Be First to Comment