Barzi2001
Barzi2001

Reputation: 1796

git config does not set vimdiff layout properly, git 2.39

I'm trying to configure vimdiff as a git merge tool, so my global git config contains the following lines:

[merge]
    tool = gvimdiff
    guitool = gvimdiff
[mergetool]
    prompt = true
[mergetool "gvimdiff"]
    layout = "LOCAL,MERGED,REMOTE"

but I am keep in having the default layout. A similar problem has reported here but it won't apply to my case because of the following reasons:

  1. I am using gvimdiff
  2. I am using git version 2.39.2 (Apple Git-143)

How should I solve it? Running on MacOsX Ventura.

Upvotes: 3

Views: 122

Answers (1)

VonC
VonC

Reputation: 1329822

That should be fixed with Git 2.45 (Q2 2024), batch 2: variants of vimdiff learned to honor mergetool.<variant>.layout settings.

See commit b21d164 (17 Feb 2024) by Kipras Melnikovas (kiprasmel).
(Merged by Junio C Hamano -- gitster -- in commit 66b1160, 27 Feb 2024)

mergetools: vimdiff: use correct tool's name when reading mergetool config

Signed-off-by: Kipras Melnikovas

The /mergetools/vimdiff script, which handles both vimdiff, nvimdiff and gvimdiff mergetools (the latter 2 simply source the vimdiff script), has a function merge_cmd() which read the layout variable from git config(man), and it would always read the value of mergetool.**vimdiff**.layout, instead of the mergetool being currently used (vimdiff or nvimdiff or gvimdiff).

It looks like in 7b5cf8b ("vimdiff: add tool documentation", 2022-03-30, Git v2.37.0-rc0 -- merge), we explained the current behavior in Documentation/config/mergetool.txt:

    The vimdiff backend uses this variable to control how its split
    windows look like. Applies even if you are using Neovim (`nvim`) or
    gVim (`gvim`) as the merge tool. See BACKEND SPECIFIC HINTS section

which makes sense why it's explained this way - the vimdiff backend is used by gvim and nvim.
But the mergetool's configuration should be separate for each tool, and indeed that's confirmed in same commit at Documentation/mergetools/vimdiff.txt:

## Variants  

Instead of `--tool=vimdiff`, you can also use one of these other variants:
* `--tool=gvimdiff`, to open gVim instead of Vim.
* `--tool=nvimdiff`, to open Neovim instead of Vim.  

When using these variants, in order to specify a custom layout you will have to set configuration variables `mergetool.gvimdiff.layout` and `mergetool.nvimdiff.layout` instead of `mergetool.vimdiff.layout` 

So it looks like we just forgot to update the 1 part of the vimdiff script that read the config variable.
Cheers.

Though, for backward compatibility, I've kept the mergetool.vimdiff fallback, so that people who unknowingly relied on it, won't have their setup broken now.

git config now includes in its man page:

mergetool.<vimdiff variant>.layout

Configure the split window layout for vimdiff's <variant>, which is any of vimdiff, nvimdiff, gvimdiff. Upon launching git mergetool with --tool=<variant> (or without --tool if merge.tool is configured as <variant>), Git will consult mergetool.<variant>.layout to determine the tool's layout.

If the variant-specific configuration is not available, vimdiff's is used as fallback.
If that too is not available, a default layout with 4 windows will be used.

To configure the layout, see the BACKEND SPECIFIC HINTS section of git-mergetool.

mergetools/vimdiff now includes in its man page:

mergetool.nvimdiff.layout instead of mergetool.vimdiff.layout (though the latter will be used as fallback if the variant-specific one is not set).

Upvotes: 1

Related Questions