Using IntelliJ as git mergetool always exits as soon as soon as it starts
Asked Answered
H

3

12

I have configured IntelliJ as my diff and mergetool on my mac, but the git launches it, the command line always returns immediately, rather than waiting for the diff to be completed, which means that the changes enacted are not reflected on disk.

My configuration is:

[mergetool "intellij"]
    cmd = /Applications/IntelliJ\\ IDEA\\ 13\\ CE.app/Contents/MacOS/idea merge \
          $(cd $(dirname \"$LOCAL\") && pwd)/$(basename \"$LOCAL\") \
          $(cd $(dirname \"$REMOTE\") && pwd)/$(basename \"$REMOTE\") \
          $(cd $(dirname \"$BASE\") && pwd)/$(basename \"$BASE\") 
          $(cd $(dirname \"$MERGED\") && pwd)/$(basename \"$MERGED\")
    trustExitCode = true

I've testing calling IntelliJ by hand without git and it also returns immediately, so I don't think this is caused by git's invocation, rather that the IntelliJ command line invocation just sends a message to open the window to an existing running instance of IntelliJ.. Is there an option to force IntelliJ to not return or spawn a new instance to make this work?

Holism answered 3/9, 2014 at 5:35 Comment(1)
are you sure that those backslash terminators are allowed inside a .gitconfig file?Publias
S
5

This works now.

Run the action "Create Command-line launcher..." to create the launch script (for me /usr/local/bin/idea.)

In .gitconfig:

[mergetool "idea"]
  cmd = idea merge \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\"
  trustExitCode = true

likewise for difftool

[difftool "idea"]
  cmd = idea diff \"$LOCAL\" \"$REMOTE\"

(Because of a bug, you may have to update the commandline launcher if you created it a while ago and have updated Intellij in the meantime.)

Swineherd answered 7/7, 2020 at 19:44 Comment(0)
S
3

There is no way to do it. There are three workarounds:

  1. Close existing application before using difftool. If there are no other windows open, mergetool will work correctly.

  2. Use second instance of IntelliJ with different caches and config home But be careful with licensing of second instance. If you use license server for example both instances will take a license from server.

  3. Add something like pause (on Windows) to a startup script. So git will call BAT file (on Windows) and this BAT file will call IntelliJ and then wait for input. After you do all what you need, you should go back to console and press any key manually.

Sunderance answered 28/11, 2014 at 14:55 Comment(0)
K
0

As Joshua Goldberg mentioned for idea, the same works for Rubymine.

Open RubyMine, then to shift + command + A, choose "Create Command-line launcher" and save. After that you can use "mine" command in terminal without issues and you should update the git config file.

[difftool "mine"]
  cmd = mine diff \"$LOCAL\" \"$REMOTE\"
[mergetool "mine"]
  cmd = mine merge \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\"
  trustExitCode = true

Thank you very much Joshua, great help!

Keewatin answered 19/8, 2022 at 7:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.