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

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, 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 7b5cf8be18 (vimdiff: add tool documentation, 2022-03-30), we explained the current behavior in Documentation/config/mergetool.txt: ``` mergetool.vimdiff.layout:: 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. Signed-off-by: Kipras Melnikovas <kipras@kipras.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kipras Melnikovas committed Feb 17, 2024 at 18:27 UTC b21d164275b9186421ebe39498be47ea9f171694
3 files changed +25 -9
Documentation/config/mergetool.txt
+13 -6
@@ -45,14 +45,21 @@ mergetool.meld.useAutoMerge::
45 value of `false` avoids using `--auto-merge` altogether, and is the
46 default value.
47
48 -mergetool.vimdiff.layout::
49 - The vimdiff backend uses this variable to control how its split
50 - windows appear. Applies even if you are using Neovim (`nvim`) or
51 - gVim (`gvim`) as the merge tool. See BACKEND SPECIFIC HINTS section
48 +mergetool.<vimdiff variant>.layout::
49 + Configure the split window layout for vimdiff's `<variant>`, which is any of `vimdiff`,
50 + `nvimdiff`, `gvimdiff`.
51 + Upon launching `git mergetool` with `--tool=<variant>` (or without `--tool`
52 + if `merge.tool` is configured as `<variant>`), Git will consult
53 + `mergetool.<variant>.layout` to determine the tool's layout. If the
54 + variant-specific configuration is not available, `vimdiff`'s is used as
55 + fallback. If that too is not available, a default layout with 4 windows
56 + will be used. To configure the layout, see the `BACKEND SPECIFIC HINTS`
57 +ifdef::git-mergetool[]
58 + section.
59 +endif::[]
60 ifndef::git-mergetool[]
53 - in linkgit:git-mergetool[1].
61 + section in linkgit:git-mergetool[1].
62 endif::[]
55 - for details.
63
64 mergetool.hideResolved::
65 During a merge, Git will automatically resolve as many conflicts as
Documentation/mergetools/vimdiff.txt
+2 -1
@@ -177,7 +177,8 @@ Instead of `--tool=vimdiff`, you can also use one of these other variants:
177
178 When using these variants, in order to specify a custom layout you will have to
179 set configuration variables `mergetool.gvimdiff.layout` and
180 -`mergetool.nvimdiff.layout` instead of `mergetool.vimdiff.layout`
180 +`mergetool.nvimdiff.layout` instead of `mergetool.vimdiff.layout` (though the
181 +latter will be used as fallback if the variant-specific one is not set).
182
183 In addition, for backwards compatibility with previous Git versions, you can
184 also append `1`, `2` or `3` to either `vimdiff` or any of the variants (ex:
mergetools/vimdiff
+10 -2
@@ -371,9 +371,17 @@ diff_cmd_help () {
371
372
373 merge_cmd () {
374 - layout=$(git config mergetool.vimdiff.layout)
374 + TOOL=$1
375
376 - case "$1" in
376 + layout=$(git config "mergetool.$TOOL.layout")
377 +
378 + # backward compatibility:
379 + if test -z "$layout"
380 + then
381 + layout=$(git config mergetool.vimdiff.layout)
382 + fi
383 +
384 + case "$TOOL" in
385 *vimdiff)
386 if test -z "$layout"
387 then