28

I'm upgrading a rails 5.2.4.1 app to rails 6. There are a few config files I want to merge instead of manually adding information from a copy of the old file.

The first time I entered m to merge the file I got the following message.

Please specify merge tool to `THOR_MERGE` env.

I did a search and found this blog post. The folder that this person found after Googling does not exist on my Mac computer.

FileMerge doesn't exist and DiffMerge is very old. I haven't found any information about using one with rails app:update.

What Mac merge tools are currently used that I can set the env var THOR_MERGE to?

4 Answers4

21

Stumbled upon this answer searching for the same thing.

You can launch vscode diff tool by setting the THOR_MERGE env variable as follows:

THOR_MERGE="code -d $1 $2"

This is assuming you have code in your PATH, which you can setup by following the instructions here.

Simon L. Brazell
  • 1,132
  • 8
  • 14
  • When I set things up this way, I get a "sh: code: command not found", even though I have VS code installed – Dave Jan 24 '22 at 15:33
  • @Dave did you follow the instruction found [here](https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line)? – Simon L. Brazell Jan 31 '22 at 01:56
8

It seems that XCode includes /usr/bin/opendiff, which is a binary that launches FileMerge.app. So I was able to:THOR_MERGE=opendiff rails app:update

pduey
  • 3,706
  • 2
  • 23
  • 31
  • when I tried this it blew up on yml files – Carl Jul 28 '22 at 13:10
  • 1
    OS X 12.6.4 gives me this error: `xcode-select: error: tool 'opendiff' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance` – Beartech Apr 20 '23 at 18:43
5

RubyMine can also be used as the merge tool. To make that work on my macOS Monterey system, I created a new Bash script at /usr/local/bin/rubymine-merge (based in part on the rubymine script provided by JetBrains Toolbox) with the following code:

#!/usr/bin/env bash

declare -- wait="-W"

bundle exec rubocop --server -A "$1"

open -na "$HOME/Library/Application Support/JetBrains/Toolbox/apps/RubyMine/ch-0/222.3739.56/RubyMine 2022.2 EAP.app/Contents/MacOS/rubymine" $wait --args merge "$2" "$1" "$2"

After this, I was able to invoke the Rails update script as follows:

THOR_MERGE=rubymine-merge bin/rails app:update

This is working as of RubyMine 2022.2.1 in mid-August of 2022.

The Rails update script seems to require that the merge tool behave as if it had received a --wait parameter, because after the last merge the script deletes all temporary files. Passing --wait as a command-line parameter seems problematic with the 2022.2 version of the command-line script, so I hard-coded the -W on line 3.

I also inserted a call to rubocop on line 5 so that the proposed changes from the Rails app:update script would already be aligned with the standards for this project. Skip that part if it's not meeting your needs. I had to use bundle exec rubocop instead of bin/rubocop because the Rails app:update script is not always running in the context of the root directory of your project.

It is suboptimal for this script be separate from the /usr/local/bin/rubymine script that is generated by JetBrains Toolbox. Every time a new version of RubyMine is installed, the path to the actual RubyMine application can change.

Daniel Ashton
  • 1,388
  • 11
  • 23
  • 1
    This is what I was looking for, but the script is going to need an update every time the Toolbox decides to change folder / app name etc. I wonder if there isn't an easier way to find the path... – Raithlin Oct 18 '22 at 11:16
3

Simple Solution:

THOR_MERGE=kdiff3 rails app:update

  • or use opendiff / meld / kdiff etc.
  • Credit to @pduey (thanks).
BenKoshy
  • 33,477
  • 14
  • 111
  • 80