Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 5: How Do I Set Up a Merge Tool to use for rails app:update?

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?

like image 314
xxx Avatar asked Mar 12 '20 20:03

xxx


People also ask

How do you upgrade gems in rails?

Find the Gem on rubygems.org and find a newer version of it that supports the requested version of Rails. Create a new branch of your source code for updating this Gem only. Update your Gemfile to use the old version of Rails and the new version of that gem; run bundle update <gem_name>


3 Answers

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.

like image 158
Simon L. Brazell Avatar answered Oct 19 '22 17:10

Simon L. Brazell


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

like image 35
pduey Avatar answered Oct 19 '22 17:10

pduey


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.

like image 2
Daniel Ashton Avatar answered Oct 19 '22 17:10

Daniel Ashton