Skip to content

Commit

Permalink
Fix invalid exit code handling for IntelliJ mergetool
Browse files Browse the repository at this point in the history
When using IntelliJ as `mergetool` and setting
`mergetool.intellij.trustExitCode` to `true`, the
`mergetool.intellij.cmd` gets called for all files immediately.
After IntelliJ gets closed for the first processed file, all other
calls errored because the temporary files passed to `idea merge` as
parameters were not valid anymore causing the app to exit.

The problem is that Git is not able to interpret or track started
IntelliJ process and fails to listen for the exit code, causing the
calls to be fired immediately. This problem can be narrowed down to
macOS while it works fine for Linux systems. See the official Git
documentation about the `mergetool` command (1) for more details.

To fix the problem the `mergetool.intellij.trustExitCode` option has
been set to `false` and `mergetool.intellij.prompt` to `true` to force
Git to wait for the user to confirm the merge is completed and the app
window has been closed before continuing with the next queued file.
The only impact is that it requires to press `y` or `n` after solving a
conflict instead of only closing the app window and waiting for it t
reopen again for the next file. This is also limited to macOS so the
impact is very small compared to the broken state when not applying the
fix.

In order to dynamically apply the configurations only for macOS systems
a `[include]` block is used setting the path to a additional file that
is only linked by "snowsaw" for macOS based hosts.

Not that the "include" statement/block is placed at the bottom of the
main Git configuration file in order to override the initial/default
block!

References:
  (1) https://git-scm.com/docs/git-mergetool

Closes GH-206
  • Loading branch information
arcticicestudio committed Jun 17, 2019
1 parent 1c969ff commit 8173420
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
7 changes: 7 additions & 0 deletions snowblocks/git/gitconfig
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,10 @@
# Usage:
# git ft <SHA1>
ft = ! git describe --tags --contains $1

# NOTE: The following "include" statements/blocks must be applied last in order to override their initial
# blocks above, otherwise the configurations won't be overridden when placed at the top of this file!

# Apply workaround to fix exit code handling for IntelliJ as merge tool when running on macOS.
[include]
path = ~/.gitconfig-macos-mergetool-exit-code
36 changes: 36 additions & 0 deletions snowblocks/git/includes/gitconfig-macos-mergetool-exit-code
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (C) 2016-present Arctic Ice Studio <[email protected]>
# Copyright (C) 2016-present Sven Greb <[email protected]>

# Project: igloo
# Repository: https://github.com/arcticicestudio/igloo
# License: MIT
# References:
# https://git-scm.com/docs/git-mergetool

# When using IntelliJ as `mergetool` and setting `mergetool.intellij.trustExitCode` to `true`,
# the `mergetool.intellij.cmd` gets called for all files immediately.
# After IntelliJ gets closed for the first processed file, all other calls will error because
# the temporary files passed to `idea merge`as parameters are not valid anymore causing the app
# to exit.
#
# The problem is that Git is not able to interpret or track started IntelliJ process and fails
# to listen for the exit code, causing the calls to be fired immediately.
# This problem can be narrowed down to macOS while it works fine for Linux systems.
# See https://git-scm.com/docs/git-mergetool for more details.
#
# To fix the problem `trustExitCode` option is set to `false` an `prompt` to `true` to force Git
# to wait for the user to confirm the merge is completed and the app window has been closed before
# continuing with the next queued file.
# The only impact is that it requires to press `y` or `n` after solving a conflict instead of only
# closing the app window and waiting for it to reopen again for the next file.
# This is also limited to macOS so the impact is very small compared to the broken state when not
# applying the fix.
#
# In order to dynamically apply the configuration file only for macOS systems , this file is loaded
# through a `[include]` block in the main Git configuration file and only linked by "snowsaw" for
# macOS based hosts.
#
# See https://github.com/arcticicestudio/igloo/issues/206 for more details.
[mergetool "intellij"]
prompt = true
trustExitCode = false
7 changes: 6 additions & 1 deletion snowblocks/git/snowblock.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@
"igloo": "gitconfig-auth-job.igloocrypt"
}
},
"~/.gitignore": null
"~/.gitignore": null,
"~/.gitconfig-macos-mergetool-exit-code": {
"hosts": {
"iceowl": "includes/gitconfig-macos-mergetool-exit-code"
}
}
}
}
]

0 comments on commit 8173420

Please sign in to comment.