{"thread":{"id":"53880","subject":"[PATCH] Support nvim as mergetool","startedAt":"2020-07-18T19:27:15Z","lastAt":"2020-07-29T21:33:52Z","messageCount":10,"participants":["pudinha","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"401739","messageId":"20200718192001.27434-1-rogi@skylittlesystem.org","threadId":"53880","inReplyTo":null,"subject":"[PATCH] Support nvim as mergetool","fromName":"pudinha","fromEmail":"rogi@skylittlesystem.org","sentAt":"2020-07-18T19:20:02Z","receivedAt":"2020-07-18T19:27:15Z","isPatch":true,"sender":{"key":"rogi@skylittlesystem.org","avatar":"https://avatars.githubusercontent.com/u/1148648?v=4"},"body":"---\nHello giters! Hope you are well!\n\nI made this little patch to support nvim as a merge tool. What do you\nthink?\n\nBest regards,\nPudinha <3\n\n mergetools/nvimdiff  | 1 +\n mergetools/nvimdiff2 | 1 +\n mergetools/nvimdiff3 | 1 +\n mergetools/vimdiff   | 9 ++++++---\n 4 files changed, 9 insertions(+), 3 deletions(-)\n create mode 100644 mergetools/nvimdiff\n create mode 100644 mergetools/nvimdiff2\n create mode 100644 mergetools/nvimdiff3\n\ndiff --git a/mergetools/nvimdiff b/mergetools/nvimdiff\nnew file mode 100644\nindex 0000000000..04a5bb0ea8\n--- /dev/null\n+++ b/mergetools/nvimdiff\n@@ -0,0 +1 @@\n+. \"$MERGE_TOOLS_DIR/vimdiff\"\ndiff --git a/mergetools/nvimdiff2 b/mergetools/nvimdiff2\nnew file mode 100644\nindex 0000000000..04a5bb0ea8\n--- /dev/null\n+++ b/mergetools/nvimdiff2\n@@ -0,0 +1 @@\n+. \"$MERGE_TOOLS_DIR/vimdiff\"\ndiff --git a/mergetools/nvimdiff3 b/mergetools/nvimdiff3\nnew file mode 100644\nindex 0000000000..04a5bb0ea8\n--- /dev/null\n+++ b/mergetools/nvimdiff3\n@@ -0,0 +1 @@\n+. \"$MERGE_TOOLS_DIR/vimdiff\"\ndiff --git a/mergetools/vimdiff b/mergetools/vimdiff\nindex 10d86f3e19..be559062ee 100644\n--- a/mergetools/vimdiff\n+++ b/mergetools/vimdiff\n@@ -5,7 +5,7 @@ diff_cmd () {\n \n merge_cmd () {\n \tcase \"$1\" in\n-\tgvimdiff|vimdiff)\n+\tnvimdiff|gvimdiff|vimdiff)\n \t\tif $base_present\n \t\tthen\n \t\t\t\"$merge_tool_path\" -f -d -c '4wincmd w | wincmd J' \\\n@@ -15,11 +15,11 @@ merge_cmd () {\n \t\t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n \t\tfi\n \t\t;;\n-\tgvimdiff2|vimdiff2)\n+\tnvimdiff2|gvimdiff2|vimdiff2)\n \t\t\"$merge_tool_path\" -f -d -c 'wincmd l' \\\n \t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n \t\t;;\n-\tgvimdiff3|vimdiff3)\n+\tnvimdiff3|gvimdiff3|vimdiff3)\n \t\tif $base_present\n \t\tthen\n \t\t\t\"$merge_tool_path\" -f -d -c 'hid | hid | hid' \\\n@@ -34,6 +34,9 @@ merge_cmd () {\n \n translate_merge_tool_path() {\n \tcase \"$1\" in\n+\tnvimdiff|nvimdiff2|nvimdiff3)\n+\t\techo nvim\n+\t\t;;\n \tgvimdiff|gvimdiff2|gvimdiff3)\n \t\techo gvim\n \t\t;;\n-- \n2.27.0\n\n"},{"id":"401744","messageId":"xmqqd04sbm6n.fsf@gitster.c.googlers.com","threadId":"53880","inReplyTo":"20200718192001.27434-1-rogi@skylittlesystem.org","subject":"Re: [PATCH] Support nvim as mergetool","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-07-18T20:30:40Z","receivedAt":"2020-07-18T20:30:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"pudinha <rogi@skylittlesystem.org> writes:\n\n> ---\n> Hello giters! Hope you are well!\n>\n> I made this little patch to support nvim as a merge tool. What do you\n> think?\n\nUninspiring.\n\nBut that is not your fault.  \n\nThe way vimdiff, vimdiff2 and vimdiff3 waste one file for each just\nto have a different name is simply bad, and the way it was extended\nto cover gvimdiff family is even more horrible.  This patch makes\nthe existing mess even worse.  That part is your fault, I'd have to\nsay.\n\nI'd rather see us explore ways to improve the current arrangement\nused to support these 6 variants before adding yet another 3 new\nones.\n\nFor example, we could add another method the backends could define,\ncall it list_tool_variants, and whenever the control flow goes from\nrun_merge_tool through setup_tool for a tool whose name ends with\n[1-9], e.g. \"foomerge3\", we first see if there is \"foomerge\" tool\nand if there is ask it if it knows about \"foomerge3\" variant by\ncalling its list_tool_variants.\n\nThat way, we probably can remove the files for vimdiff2, vimdiff3,\ngvimdiff2 and gvimdiff3 (gvimdiff needs to stay there, as we do not\nwant to make the name derivation rule too complex) only to hold a\nsingle line \". vimdiff\".  Then the next person who adds yet another\nset of backends based on a yet another reimplementation or skin of\nvim would only have to add a single file in mergetools/ directory,\nnot three.\n\nHmm?\n"},{"id":"401748","messageId":"20200719042335.3913-2-rogi@skylittlesystem.org","threadId":"53880","inReplyTo":"20200718192001.27434-1-rogi@skylittlesystem.org","subject":"[PATCH v2 1/2] Refactor vimdiff and bc merge tool variants","fromName":"pudinha","fromEmail":"rogi@skylittlesystem.org","sentAt":"2020-07-19T04:23:37Z","receivedAt":"2020-07-19T04:28:12Z","isPatch":true,"sender":{"key":"rogi@skylittlesystem.org","avatar":"https://avatars.githubusercontent.com/u/1148648?v=4"},"body":"The merge tools vimdiff2, vimdiff3, gvimdiff2, gvimdiff3 and bc3 are all\nvariants of the main tools vimdiff and bc. They are implemented in the\nmain and a one-liner script that just sources it exist for each.\n\nThis patch allows variants ending in [0-9] to be correctly wired without\nthe need for such one-liners, so instead of 5 scripts, only 1 (gvimdiff)\nis needed.\n---\n git-mergetool--lib.sh | 28 +++++++++++++++++++++++-----\n mergetools/bc         |  5 +++++\n mergetools/bc3        |  1 -\n mergetools/gvimdiff2  |  1 -\n mergetools/gvimdiff3  |  1 -\n mergetools/vimdiff    |  8 ++++++++\n mergetools/vimdiff2   |  1 -\n mergetools/vimdiff3   |  1 -\n 8 files changed, 36 insertions(+), 10 deletions(-)\n delete mode 100644 mergetools/bc3\n delete mode 100644 mergetools/gvimdiff2\n delete mode 100644 mergetools/gvimdiff3\n delete mode 100644 mergetools/vimdiff2\n delete mode 100644 mergetools/vimdiff3\n\ndiff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh\nindex 204a5acd66..29fecc340f 100644\n--- a/git-mergetool--lib.sh\n+++ b/git-mergetool--lib.sh\n@@ -43,7 +43,14 @@ show_tool_names () {\n \n \tshown_any=\n \t( cd \"$MERGE_TOOLS_DIR\" && ls ) | {\n-\t\twhile read toolname\n+\t\twhile read scriptname\n+\t\tdo\n+\t\t\tsetup_tool \"$scriptname\" 2>/dev/null\n+\t\t\tvariants=\"$variants$(list_tool_variants)\\n\"\n+\t\tdone\n+\t\tvariants=\"$(echo \"$variants\" | sort | uniq)\"\n+\n+\t\tfor toolname in $variants\n \t\tdo\n \t\t\tif setup_tool \"$toolname\" 2>/dev/null &&\n \t\t\t\t(eval \"$condition\" \"$toolname\")\n@@ -157,6 +164,10 @@ setup_tool () {\n \t\techo \"$1\"\n \t}\n \n+\tlist_tool_variants () {\n+\t\techo \"$tool\"\n+\t}\n+\n \t# Most tools' exit codes cannot be trusted, so By default we ignore\n \t# their exit code and check the merged file's modification time in\n \t# check_unchanged() to determine whether or not the merge was\n@@ -178,19 +189,26 @@ setup_tool () {\n \t\tfalse\n \t}\n \n-\n-\tif ! test -f \"$MERGE_TOOLS_DIR/$tool\"\n+\tif test -f \"$MERGE_TOOLS_DIR/$tool\"\n \tthen\n+\t\t. \"$MERGE_TOOLS_DIR/$tool\"\n+\telif test -f \"$MERGE_TOOLS_DIR/${tool%[0-9]}\"\n+\tthen\n+\t\t. \"$MERGE_TOOLS_DIR/${tool%[0-9]}\"\n+\telse\n \t\tsetup_user_tool\n \t\treturn $?\n \tfi\n \n-\t# Load the redefined functions\n-\t. \"$MERGE_TOOLS_DIR/$tool\"\n \t# Now let the user override the default command for the tool.  If\n \t# they have not done so then this will return 1 which we ignore.\n \tsetup_user_tool\n \n+\tif ! list_tool_variants | grep -q \"^$tool$\"\n+\tthen\n+\t\treturn 1\n+\tfi\n+\n \tif merge_mode && ! can_merge\n \tthen\n \t\techo \"error: '$tool' can not be used to resolve merges\" >&2\ndiff --git a/mergetools/bc b/mergetools/bc\nindex 3a69e60faa..a89086ee72 100644\n--- a/mergetools/bc\n+++ b/mergetools/bc\n@@ -21,3 +21,8 @@ translate_merge_tool_path() {\n \t\techo bcompare\n \tfi\n }\n+\n+list_tool_variants () {\n+\techo bc\n+\techo bc3\n+}\ndiff --git a/mergetools/bc3 b/mergetools/bc3\ndeleted file mode 100644\nindex 5d8dd48184..0000000000\n--- a/mergetools/bc3\n+++ /dev/null\n@@ -1 +0,0 @@\n-. \"$MERGE_TOOLS_DIR/bc\"\ndiff --git a/mergetools/gvimdiff2 b/mergetools/gvimdiff2\ndeleted file mode 100644\nindex 04a5bb0ea8..0000000000\n--- a/mergetools/gvimdiff2\n+++ /dev/null\n@@ -1 +0,0 @@\n-. \"$MERGE_TOOLS_DIR/vimdiff\"\ndiff --git a/mergetools/gvimdiff3 b/mergetools/gvimdiff3\ndeleted file mode 100644\nindex 04a5bb0ea8..0000000000\n--- a/mergetools/gvimdiff3\n+++ /dev/null\n@@ -1 +0,0 @@\n-. \"$MERGE_TOOLS_DIR/vimdiff\"\ndiff --git a/mergetools/vimdiff b/mergetools/vimdiff\nindex 10d86f3e19..3925e1fc3e 100644\n--- a/mergetools/vimdiff\n+++ b/mergetools/vimdiff\n@@ -46,3 +46,11 @@ translate_merge_tool_path() {\n exit_code_trustable () {\n \ttrue\n }\n+\n+list_tool_variants () {\n+\tfor prefix in '' g; do\n+\t\tfor suffix in '' 2 3; do\n+\t\t\techo \"${prefix}vimdiff${suffix}\"\n+\t\tdone\n+\tdone\n+}\ndiff --git a/mergetools/vimdiff2 b/mergetools/vimdiff2\ndeleted file mode 100644\nindex 04a5bb0ea8..0000000000\n--- a/mergetools/vimdiff2\n+++ /dev/null\n@@ -1 +0,0 @@\n-. \"$MERGE_TOOLS_DIR/vimdiff\"\ndiff --git a/mergetools/vimdiff3 b/mergetools/vimdiff3\ndeleted file mode 100644\nindex 04a5bb0ea8..0000000000\n--- a/mergetools/vimdiff3\n+++ /dev/null\n@@ -1 +0,0 @@\n-. \"$MERGE_TOOLS_DIR/vimdiff\"\n-- \n2.27.0\n\n"},{"id":"401750","messageId":"20200719042335.3913-1-rogi@skylittlesystem.org","threadId":"53880","inReplyTo":"20200718192001.27434-1-rogi@skylittlesystem.org","subject":"[PATCH v2 0/2] Support nvim as merge tool","fromName":"pudinha","fromEmail":"rogi@skylittlesystem.org","sentAt":"2020-07-19T04:23:35Z","receivedAt":"2020-07-19T04:28:12Z","isPatch":true,"sender":{"key":"rogi@skylittlesystem.org","avatar":"https://avatars.githubusercontent.com/u/1148648?v=4"},"body":"> For example, we could add another method the backends could define,\n> call it list_tool_variants, and whenever the control flow goes from\n> run_merge_tool through setup_tool for a tool whose name ends with\n> [1-9], e.g. \"foomerge3\", we first see if there is \"foomerge\" tool\n> and if there is ask it if it knows about \"foomerge3\" variant by\n> calling its list_tool_variants.\n>\n> That way, we probably can remove the files for vimdiff2, vimdiff3,\n> gvimdiff2 and gvimdiff3 (gvimdiff needs to stay there, as we do not\n> want to make the name derivation rule too complex) only to hold a\n> single line \". vimdiff\".  Then the next person who adds yet another\n> set of backends based on a yet another reimplementation or skin of\n> vim would only have to add a single file in mergetools/ directory,\n> not three.\n\nThis is what I managed to do.\n\npudinha (2):\n  Refactor vimdiff and bc merge tool variants\n  Support nvim as merge tool\n\n contrib/completion/git-completion.bash |  4 +--\n git-mergetool--lib.sh                  | 35 ++++++++++++++++++++------\n mergetools/bc                          |  5 ++++\n mergetools/bc3                         |  1 -\n mergetools/gvimdiff3                   |  1 -\n mergetools/{gvimdiff2 => nvimdiff}     |  0\n mergetools/vimdiff                     | 21 ++++++++++++----\n mergetools/vimdiff2                    |  1 -\n mergetools/vimdiff3                    |  1 -\n 9 files changed, 51 insertions(+), 18 deletions(-)\n delete mode 100644 mergetools/bc3\n delete mode 100644 mergetools/gvimdiff3\n rename mergetools/{gvimdiff2 => nvimdiff} (100%)\n delete mode 100644 mergetools/vimdiff2\n delete mode 100644 mergetools/vimdiff3\n\n-- \n2.27.0\n\n"},{"id":"401749","messageId":"20200719042335.3913-3-rogi@skylittlesystem.org","threadId":"53880","inReplyTo":"20200718192001.27434-1-rogi@skylittlesystem.org","subject":"[PATCH v2 2/2] Support nvim as merge tool","fromName":"pudinha","fromEmail":"rogi@skylittlesystem.org","sentAt":"2020-07-19T04:23:38Z","receivedAt":"2020-07-19T04:28:13Z","isPatch":true,"sender":{"key":"rogi@skylittlesystem.org","avatar":"https://avatars.githubusercontent.com/u/1148648?v=4"},"body":"---\n contrib/completion/git-completion.bash |  4 ++--\n git-mergetool--lib.sh                  |  7 +++++--\n mergetools/nvimdiff                    |  1 +\n mergetools/vimdiff                     | 15 +++++++++------\n 4 files changed, 17 insertions(+), 10 deletions(-)\n create mode 100644 mergetools/nvimdiff\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex ee468ea3b0..aed08f8df5 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1712,8 +1712,8 @@ _git_diff ()\n }\n \n __git_mergetools_common=\"diffuse diffmerge ecmerge emerge kdiff3 meld opendiff\n-\t\t\ttkdiff vimdiff gvimdiff xxdiff araxis p4merge bc\n-\t\t\tcodecompare smerge\n+\t\t\ttkdiff vimdiff nvimdiff gvimdiff xxdiff araxis p4merge\n+\t\t\tbc codecompare smerge\n \"\n \n _git_difftool ()\ndiff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh\nindex 29fecc340f..2defef28cd 100644\n--- a/git-mergetool--lib.sh\n+++ b/git-mergetool--lib.sh\n@@ -304,11 +304,14 @@ list_merge_tool_candidates () {\n \t\ttools=\"$tools smerge\"\n \tfi\n \tcase \"${VISUAL:-$EDITOR}\" in\n+\t*nvim*)\n+\t\ttools=\"$tools nvimdiff vimdiff emerge\"\n+\t\t;;\n \t*vim*)\n-\t\ttools=\"$tools vimdiff emerge\"\n+\t\ttools=\"$tools vimdiff nvimdiff emerge\"\n \t\t;;\n \t*)\n-\t\ttools=\"$tools emerge vimdiff\"\n+\t\ttools=\"$tools emerge vimdiff nvimdiff\"\n \t\t;;\n \tesac\n }\ndiff --git a/mergetools/nvimdiff b/mergetools/nvimdiff\nnew file mode 100644\nindex 0000000000..04a5bb0ea8\n--- /dev/null\n+++ b/mergetools/nvimdiff\n@@ -0,0 +1 @@\n+. \"$MERGE_TOOLS_DIR/vimdiff\"\ndiff --git a/mergetools/vimdiff b/mergetools/vimdiff\nindex 3925e1fc3e..abc8ce4ec4 100644\n--- a/mergetools/vimdiff\n+++ b/mergetools/vimdiff\n@@ -5,7 +5,7 @@ diff_cmd () {\n \n merge_cmd () {\n \tcase \"$1\" in\n-\tgvimdiff|vimdiff)\n+\t*vimdiff)\n \t\tif $base_present\n \t\tthen\n \t\t\t\"$merge_tool_path\" -f -d -c '4wincmd w | wincmd J' \\\n@@ -15,11 +15,11 @@ merge_cmd () {\n \t\t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n \t\tfi\n \t\t;;\n-\tgvimdiff2|vimdiff2)\n+\t*vimdiff2)\n \t\t\"$merge_tool_path\" -f -d -c 'wincmd l' \\\n \t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n \t\t;;\n-\tgvimdiff3|vimdiff3)\n+\t*vimdiff3)\n \t\tif $base_present\n \t\tthen\n \t\t\t\"$merge_tool_path\" -f -d -c 'hid | hid | hid' \\\n@@ -34,10 +34,13 @@ merge_cmd () {\n \n translate_merge_tool_path() {\n \tcase \"$1\" in\n-\tgvimdiff|gvimdiff2|gvimdiff3)\n+\tnvimdiff*)\n+\t\techo nvim\n+\t\t;;\n+\tgvimdiff*)\n \t\techo gvim\n \t\t;;\n-\tvimdiff|vimdiff2|vimdiff3)\n+\tvimdiff*)\n \t\techo vim\n \t\t;;\n \tesac\n@@ -48,7 +51,7 @@ exit_code_trustable () {\n }\n \n list_tool_variants () {\n-\tfor prefix in '' g; do\n+\tfor prefix in '' g n; do\n \t\tfor suffix in '' 2 3; do\n \t\t\techo \"${prefix}vimdiff${suffix}\"\n \t\tdone\n-- \n2.27.0\n\n"},{"id":"401779","messageId":"xmqqd04q9g14.fsf@gitster.c.googlers.com","threadId":"53880","inReplyTo":"20200719042335.3913-2-rogi@skylittlesystem.org","subject":"Re: [PATCH v2 1/2] Refactor vimdiff and bc merge tool variants","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-07-20T18:51:03Z","receivedAt":"2020-07-20T18:51:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"pudinha <rogi@skylittlesystem.org> writes:\n\n> Subject: Re: [PATCH v2 1/2] Refactor vimdiff and bc merge tool variants\n\ncf. https://git-scm.com/docs/SubmittingPatches#describe-changes\n\nTwo tricks to pick a good title are:\n\n - Read a pageful or two of \"git shortlog --no-merges\" output to get\n   accustomed to the general pattern in the entire project.  It\n   would become clear why titles with \"area:\" prefix help the\n   patches with them easier to locate.\n\n - Read a pageful of \"git shortlog --no-merges -- mergetools\"\n   (i.e. the same but limited to the files you are touching) to see\n   how the changes that contributed over time to build the subsystem\n   are called, so that the new patches can fit in the pattern.\n\n> The merge tools vimdiff2, vimdiff3, gvimdiff2, gvimdiff3 and bc3 are all\n> variants of the main tools vimdiff and bc. They are implemented in the\n> main and a one-liner script that just sources it exist for each.\n>\n> This patch allows variants ending in [0-9] to be correctly wired without\n> the need for such one-liners, so instead of 5 scripts, only 1 (gvimdiff)\n> is needed.\n\nWell explained.  The final paragraph could be made more in line with\nthe existing commit log messages by writing in the imperative mood\n(e.g. \"Introduce a new list_tool_variants method, and when a tool\nwhose name ends with a digit is asked for, and if there is no such\nscript in mergetools/ directoroy, ask the tool with the name without\nthe final digit, if exists, if it knows how to handle the variant.\nThat way, instead of 5 scriptss, ...\"), but what is written above is\nalready good enough.\n\n> ---\n\ncf. https://git-scm.com/docs/SubmittingPatches#sign-off\n\nThanks.\n\n>  git-mergetool--lib.sh | 28 +++++++++++++++++++++++-----\n>  mergetools/bc         |  5 +++++\n>  mergetools/bc3        |  1 -\n>  mergetools/gvimdiff2  |  1 -\n>  mergetools/gvimdiff3  |  1 -\n>  mergetools/vimdiff    |  8 ++++++++\n>  mergetools/vimdiff2   |  1 -\n>  mergetools/vimdiff3   |  1 -\n>  8 files changed, 36 insertions(+), 10 deletions(-)\n>  delete mode 100644 mergetools/bc3\n>  delete mode 100644 mergetools/gvimdiff2\n>  delete mode 100644 mergetools/gvimdiff3\n>  delete mode 100644 mergetools/vimdiff2\n>  delete mode 100644 mergetools/vimdiff3\n>\n> diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh\n> index 204a5acd66..29fecc340f 100644\n> --- a/git-mergetool--lib.sh\n> +++ b/git-mergetool--lib.sh\n> @@ -43,7 +43,14 @@ show_tool_names () {\n>  \n>  \tshown_any=\n>  \t( cd \"$MERGE_TOOLS_DIR\" && ls ) | {\n> -\t\twhile read toolname\n> +\t\twhile read scriptname\n> +\t\tdo\n> +\t\t\tsetup_tool \"$scriptname\" 2>/dev/null\n> +\t\t\tvariants=\"$variants$(list_tool_variants)\\n\"\n> +\t\tdone\n> +\t\tvariants=\"$(echo \"$variants\" | sort | uniq)\"\n> +\n> +\t\tfor toolname in $variants\n>  \t\tdo\n>  \t\t\tif setup_tool \"$toolname\" 2>/dev/null &&\n>  \t\t\t\t(eval \"$condition\" \"$toolname\")\n> @@ -157,6 +164,10 @@ setup_tool () {\n>  \t\techo \"$1\"\n>  \t}\n>  \n> +\tlist_tool_variants () {\n> +\t\techo \"$tool\"\n> +\t}\n> +\n>  \t# Most tools' exit codes cannot be trusted, so By default we ignore\n>  \t# their exit code and check the merged file's modification time in\n>  \t# check_unchanged() to determine whether or not the merge was\n> @@ -178,19 +189,26 @@ setup_tool () {\n>  \t\tfalse\n>  \t}\n>  \n> -\n> -\tif ! test -f \"$MERGE_TOOLS_DIR/$tool\"\n> +\tif test -f \"$MERGE_TOOLS_DIR/$tool\"\n>  \tthen\n> +\t\t. \"$MERGE_TOOLS_DIR/$tool\"\n> +\telif test -f \"$MERGE_TOOLS_DIR/${tool%[0-9]}\"\n> +\tthen\n> +\t\t. \"$MERGE_TOOLS_DIR/${tool%[0-9]}\"\n> +\telse\n\nNice---if the thing has a custom script in mergetools/ then we do\nnot do anything special, but if a script is missing for a tool whose\nname ends with a digit, and a script exists for a tool with the same\nname without that digit, we try to use that instead, and we make\nsure it does support the named variant or bail out later...\n\n>  \t\tsetup_user_tool\n>  \t\treturn $?\n>  \tfi\n>  \n> -\t# Load the redefined functions\n> -\t. \"$MERGE_TOOLS_DIR/$tool\"\n>  \t# Now let the user override the default command for the tool.  If\n>  \t# they have not done so then this will return 1 which we ignore.\n>  \tsetup_user_tool\n>  \n> +\tif ! list_tool_variants | grep -q \"^$tool$\"\n> +\tthen\n> +\t\treturn 1\n> +\tfi\n\n... like this.  Excellent.\n"},{"id":"401781","messageId":"xmqq8sfe9fz3.fsf@gitster.c.googlers.com","threadId":"53880","inReplyTo":"20200719042335.3913-3-rogi@skylittlesystem.org","subject":"Re: [PATCH v2 2/2] Support nvim as merge tool","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-07-20T18:52:16Z","receivedAt":"2020-07-20T18:52:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"pudinha <rogi@skylittlesystem.org> writes:\n\n> Subject: Re: [PATCH v2 2/2] Support nvim as merge tool\n\nPerhaps \"mergetools: add support for nvimdiff family\" or something\nalong that line.\n\n> ---\n\nMissing sign-off.\n\nThanks.\n\n\n>  contrib/completion/git-completion.bash |  4 ++--\n>  git-mergetool--lib.sh                  |  7 +++++--\n>  mergetools/nvimdiff                    |  1 +\n>  mergetools/vimdiff                     | 15 +++++++++------\n>  4 files changed, 17 insertions(+), 10 deletions(-)\n>  create mode 100644 mergetools/nvimdiff\n>\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index ee468ea3b0..aed08f8df5 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -1712,8 +1712,8 @@ _git_diff ()\n>  }\n>  \n>  __git_mergetools_common=\"diffuse diffmerge ecmerge emerge kdiff3 meld opendiff\n> -\t\t\ttkdiff vimdiff gvimdiff xxdiff araxis p4merge bc\n> -\t\t\tcodecompare smerge\n> +\t\t\ttkdiff vimdiff nvimdiff gvimdiff xxdiff araxis p4merge\n> +\t\t\tbc codecompare smerge\n>  \"\n>  \n>  _git_difftool ()\n> diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh\n> index 29fecc340f..2defef28cd 100644\n> --- a/git-mergetool--lib.sh\n> +++ b/git-mergetool--lib.sh\n> @@ -304,11 +304,14 @@ list_merge_tool_candidates () {\n>  \t\ttools=\"$tools smerge\"\n>  \tfi\n>  \tcase \"${VISUAL:-$EDITOR}\" in\n> +\t*nvim*)\n> +\t\ttools=\"$tools nvimdiff vimdiff emerge\"\n> +\t\t;;\n>  \t*vim*)\n> -\t\ttools=\"$tools vimdiff emerge\"\n> +\t\ttools=\"$tools vimdiff nvimdiff emerge\"\n>  \t\t;;\n>  \t*)\n> -\t\ttools=\"$tools emerge vimdiff\"\n> +\t\ttools=\"$tools emerge vimdiff nvimdiff\"\n>  \t\t;;\n>  \tesac\n>  }\n> diff --git a/mergetools/nvimdiff b/mergetools/nvimdiff\n> new file mode 100644\n> index 0000000000..04a5bb0ea8\n> --- /dev/null\n> +++ b/mergetools/nvimdiff\n> @@ -0,0 +1 @@\n> +. \"$MERGE_TOOLS_DIR/vimdiff\"\n> diff --git a/mergetools/vimdiff b/mergetools/vimdiff\n> index 3925e1fc3e..abc8ce4ec4 100644\n> --- a/mergetools/vimdiff\n> +++ b/mergetools/vimdiff\n> @@ -5,7 +5,7 @@ diff_cmd () {\n>  \n>  merge_cmd () {\n>  \tcase \"$1\" in\n> -\tgvimdiff|vimdiff)\n> +\t*vimdiff)\n>  \t\tif $base_present\n>  \t\tthen\n>  \t\t\t\"$merge_tool_path\" -f -d -c '4wincmd w | wincmd J' \\\n> @@ -15,11 +15,11 @@ merge_cmd () {\n>  \t\t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n>  \t\tfi\n>  \t\t;;\n> -\tgvimdiff2|vimdiff2)\n> +\t*vimdiff2)\n>  \t\t\"$merge_tool_path\" -f -d -c 'wincmd l' \\\n>  \t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n>  \t\t;;\n> -\tgvimdiff3|vimdiff3)\n> +\t*vimdiff3)\n>  \t\tif $base_present\n>  \t\tthen\n>  \t\t\t\"$merge_tool_path\" -f -d -c 'hid | hid | hid' \\\n> @@ -34,10 +34,13 @@ merge_cmd () {\n>  \n>  translate_merge_tool_path() {\n>  \tcase \"$1\" in\n> -\tgvimdiff|gvimdiff2|gvimdiff3)\n> +\tnvimdiff*)\n> +\t\techo nvim\n> +\t\t;;\n> +\tgvimdiff*)\n>  \t\techo gvim\n>  \t\t;;\n> -\tvimdiff|vimdiff2|vimdiff3)\n> +\tvimdiff*)\n>  \t\techo vim\n>  \t\t;;\n>  \tesac\n> @@ -48,7 +51,7 @@ exit_code_trustable () {\n>  }\n>  \n>  list_tool_variants () {\n> -\tfor prefix in '' g; do\n> +\tfor prefix in '' g n; do\n>  \t\tfor suffix in '' 2 3; do\n>  \t\t\techo \"${prefix}vimdiff${suffix}\"\n>  \t\tdone\n"},{"id":"402381","messageId":"20200729213113.15927-1-rogi@skylittlesystem.org","threadId":"53880","inReplyTo":"20200719042335.3913-1-rogi@skylittlesystem.org","subject":"[PATCH v3 0/2] mergetools: add support for nvimdiff (neovim) family","fromName":"pudinha","fromEmail":"rogi@skylittlesystem.org","sentAt":"2020-07-29T21:31:11Z","receivedAt":"2020-07-29T21:32:20Z","isPatch":true,"sender":{"key":"rogi@skylittlesystem.org","avatar":"https://avatars.githubusercontent.com/u/1148648?v=4"},"body":"Junio,\n\nthanks for your time. I think I addressed all your comments regarding\nthe commit messages. One of them is a bit long, but I saw some others\nare too and I'd rather have it long than not descriptive enough.\n\nPlease, let me know if anything else needs changing.\n\nBest regards\n\npudinha (2):\n  mergetool--lib: improve support for vimdiff-style tool variants\n  mergetools: add support for nvimdiff (neovim) family\n\n contrib/completion/git-completion.bash |  4 +--\n git-mergetool--lib.sh                  | 35 ++++++++++++++++++++------\n mergetools/bc                          |  5 ++++\n mergetools/bc3                         |  1 -\n mergetools/gvimdiff3                   |  1 -\n mergetools/{gvimdiff2 => nvimdiff}     |  0\n mergetools/vimdiff                     | 21 ++++++++++++----\n mergetools/vimdiff2                    |  1 -\n mergetools/vimdiff3                    |  1 -\n 9 files changed, 51 insertions(+), 18 deletions(-)\n delete mode 100644 mergetools/bc3\n delete mode 100644 mergetools/gvimdiff3\n rename mergetools/{gvimdiff2 => nvimdiff} (100%)\n delete mode 100644 mergetools/vimdiff2\n delete mode 100644 mergetools/vimdiff3\n\n-- \n2.28.0\n\n"},{"id":"402382","messageId":"20200729213113.15927-2-rogi@skylittlesystem.org","threadId":"53880","inReplyTo":"20200729213113.15927-1-rogi@skylittlesystem.org","subject":"[PATCH v3 1/2] mergetool--lib: improve support for vimdiff-style tool variants","fromName":"pudinha","fromEmail":"rogi@skylittlesystem.org","sentAt":"2020-07-29T21:31:12Z","receivedAt":"2020-07-29T21:32:51Z","isPatch":true,"sender":{"key":"rogi@skylittlesystem.org","avatar":"https://avatars.githubusercontent.com/u/1148648?v=4"},"body":"The merge tools vimdiff2, vimdiff3, gvimdiff2, gvimdiff3 and bc3 are all\nvariants of the main tools vimdiff and bc. They are implemented in the\nmain and a one-liner script that just sources it exist for each.\n\nAllow variants ending in [0-9] to be correctly wired without the need\nfor such one-liners, so instead of 5 scripts, only 1 (gvimdiff) is\nneeded.\n\nSigned-off-by: pudinha <rogi@skylittlesystem.org>\n---\n git-mergetool--lib.sh | 28 +++++++++++++++++++++++-----\n mergetools/bc         |  5 +++++\n mergetools/bc3        |  1 -\n mergetools/gvimdiff2  |  1 -\n mergetools/gvimdiff3  |  1 -\n mergetools/vimdiff    |  8 ++++++++\n mergetools/vimdiff2   |  1 -\n mergetools/vimdiff3   |  1 -\n 8 files changed, 36 insertions(+), 10 deletions(-)\n delete mode 100644 mergetools/bc3\n delete mode 100644 mergetools/gvimdiff2\n delete mode 100644 mergetools/gvimdiff3\n delete mode 100644 mergetools/vimdiff2\n delete mode 100644 mergetools/vimdiff3\n\ndiff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh\nindex 204a5acd66..29fecc340f 100644\n--- a/git-mergetool--lib.sh\n+++ b/git-mergetool--lib.sh\n@@ -43,7 +43,14 @@ show_tool_names () {\n \n \tshown_any=\n \t( cd \"$MERGE_TOOLS_DIR\" && ls ) | {\n-\t\twhile read toolname\n+\t\twhile read scriptname\n+\t\tdo\n+\t\t\tsetup_tool \"$scriptname\" 2>/dev/null\n+\t\t\tvariants=\"$variants$(list_tool_variants)\\n\"\n+\t\tdone\n+\t\tvariants=\"$(echo \"$variants\" | sort | uniq)\"\n+\n+\t\tfor toolname in $variants\n \t\tdo\n \t\t\tif setup_tool \"$toolname\" 2>/dev/null &&\n \t\t\t\t(eval \"$condition\" \"$toolname\")\n@@ -157,6 +164,10 @@ setup_tool () {\n \t\techo \"$1\"\n \t}\n \n+\tlist_tool_variants () {\n+\t\techo \"$tool\"\n+\t}\n+\n \t# Most tools' exit codes cannot be trusted, so By default we ignore\n \t# their exit code and check the merged file's modification time in\n \t# check_unchanged() to determine whether or not the merge was\n@@ -178,19 +189,26 @@ setup_tool () {\n \t\tfalse\n \t}\n \n-\n-\tif ! test -f \"$MERGE_TOOLS_DIR/$tool\"\n+\tif test -f \"$MERGE_TOOLS_DIR/$tool\"\n \tthen\n+\t\t. \"$MERGE_TOOLS_DIR/$tool\"\n+\telif test -f \"$MERGE_TOOLS_DIR/${tool%[0-9]}\"\n+\tthen\n+\t\t. \"$MERGE_TOOLS_DIR/${tool%[0-9]}\"\n+\telse\n \t\tsetup_user_tool\n \t\treturn $?\n \tfi\n \n-\t# Load the redefined functions\n-\t. \"$MERGE_TOOLS_DIR/$tool\"\n \t# Now let the user override the default command for the tool.  If\n \t# they have not done so then this will return 1 which we ignore.\n \tsetup_user_tool\n \n+\tif ! list_tool_variants | grep -q \"^$tool$\"\n+\tthen\n+\t\treturn 1\n+\tfi\n+\n \tif merge_mode && ! can_merge\n \tthen\n \t\techo \"error: '$tool' can not be used to resolve merges\" >&2\ndiff --git a/mergetools/bc b/mergetools/bc\nindex 3a69e60faa..a89086ee72 100644\n--- a/mergetools/bc\n+++ b/mergetools/bc\n@@ -21,3 +21,8 @@ translate_merge_tool_path() {\n \t\techo bcompare\n \tfi\n }\n+\n+list_tool_variants () {\n+\techo bc\n+\techo bc3\n+}\ndiff --git a/mergetools/bc3 b/mergetools/bc3\ndeleted file mode 100644\nindex 5d8dd48184..0000000000\n--- a/mergetools/bc3\n+++ /dev/null\n@@ -1 +0,0 @@\n-. \"$MERGE_TOOLS_DIR/bc\"\ndiff --git a/mergetools/gvimdiff2 b/mergetools/gvimdiff2\ndeleted file mode 100644\nindex 04a5bb0ea8..0000000000\n--- a/mergetools/gvimdiff2\n+++ /dev/null\n@@ -1 +0,0 @@\n-. \"$MERGE_TOOLS_DIR/vimdiff\"\ndiff --git a/mergetools/gvimdiff3 b/mergetools/gvimdiff3\ndeleted file mode 100644\nindex 04a5bb0ea8..0000000000\n--- a/mergetools/gvimdiff3\n+++ /dev/null\n@@ -1 +0,0 @@\n-. \"$MERGE_TOOLS_DIR/vimdiff\"\ndiff --git a/mergetools/vimdiff b/mergetools/vimdiff\nindex 10d86f3e19..3925e1fc3e 100644\n--- a/mergetools/vimdiff\n+++ b/mergetools/vimdiff\n@@ -46,3 +46,11 @@ translate_merge_tool_path() {\n exit_code_trustable () {\n \ttrue\n }\n+\n+list_tool_variants () {\n+\tfor prefix in '' g; do\n+\t\tfor suffix in '' 2 3; do\n+\t\t\techo \"${prefix}vimdiff${suffix}\"\n+\t\tdone\n+\tdone\n+}\ndiff --git a/mergetools/vimdiff2 b/mergetools/vimdiff2\ndeleted file mode 100644\nindex 04a5bb0ea8..0000000000\n--- a/mergetools/vimdiff2\n+++ /dev/null\n@@ -1 +0,0 @@\n-. \"$MERGE_TOOLS_DIR/vimdiff\"\ndiff --git a/mergetools/vimdiff3 b/mergetools/vimdiff3\ndeleted file mode 100644\nindex 04a5bb0ea8..0000000000\n--- a/mergetools/vimdiff3\n+++ /dev/null\n@@ -1 +0,0 @@\n-. \"$MERGE_TOOLS_DIR/vimdiff\"\n-- \n2.28.0\n\n"},{"id":"402383","messageId":"20200729213113.15927-3-rogi@skylittlesystem.org","threadId":"53880","inReplyTo":"20200729213113.15927-1-rogi@skylittlesystem.org","subject":"[PATCH v3 2/2] mergetools: add support for nvimdiff (neovim) family","fromName":"pudinha","fromEmail":"rogi@skylittlesystem.org","sentAt":"2020-07-29T21:31:13Z","receivedAt":"2020-07-29T21:33:52Z","isPatch":true,"sender":{"key":"rogi@skylittlesystem.org","avatar":"https://avatars.githubusercontent.com/u/1148648?v=4"},"body":"Signed-off-by: pudinha <rogi@skylittlesystem.org>\n---\n contrib/completion/git-completion.bash |  4 ++--\n git-mergetool--lib.sh                  |  7 +++++--\n mergetools/nvimdiff                    |  1 +\n mergetools/vimdiff                     | 15 +++++++++------\n 4 files changed, 17 insertions(+), 10 deletions(-)\n create mode 100644 mergetools/nvimdiff\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex ee468ea3b0..aed08f8df5 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1712,8 +1712,8 @@ _git_diff ()\n }\n \n __git_mergetools_common=\"diffuse diffmerge ecmerge emerge kdiff3 meld opendiff\n-\t\t\ttkdiff vimdiff gvimdiff xxdiff araxis p4merge bc\n-\t\t\tcodecompare smerge\n+\t\t\ttkdiff vimdiff nvimdiff gvimdiff xxdiff araxis p4merge\n+\t\t\tbc codecompare smerge\n \"\n \n _git_difftool ()\ndiff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh\nindex 29fecc340f..2defef28cd 100644\n--- a/git-mergetool--lib.sh\n+++ b/git-mergetool--lib.sh\n@@ -304,11 +304,14 @@ list_merge_tool_candidates () {\n \t\ttools=\"$tools smerge\"\n \tfi\n \tcase \"${VISUAL:-$EDITOR}\" in\n+\t*nvim*)\n+\t\ttools=\"$tools nvimdiff vimdiff emerge\"\n+\t\t;;\n \t*vim*)\n-\t\ttools=\"$tools vimdiff emerge\"\n+\t\ttools=\"$tools vimdiff nvimdiff emerge\"\n \t\t;;\n \t*)\n-\t\ttools=\"$tools emerge vimdiff\"\n+\t\ttools=\"$tools emerge vimdiff nvimdiff\"\n \t\t;;\n \tesac\n }\ndiff --git a/mergetools/nvimdiff b/mergetools/nvimdiff\nnew file mode 100644\nindex 0000000000..04a5bb0ea8\n--- /dev/null\n+++ b/mergetools/nvimdiff\n@@ -0,0 +1 @@\n+. \"$MERGE_TOOLS_DIR/vimdiff\"\ndiff --git a/mergetools/vimdiff b/mergetools/vimdiff\nindex 3925e1fc3e..abc8ce4ec4 100644\n--- a/mergetools/vimdiff\n+++ b/mergetools/vimdiff\n@@ -5,7 +5,7 @@ diff_cmd () {\n \n merge_cmd () {\n \tcase \"$1\" in\n-\tgvimdiff|vimdiff)\n+\t*vimdiff)\n \t\tif $base_present\n \t\tthen\n \t\t\t\"$merge_tool_path\" -f -d -c '4wincmd w | wincmd J' \\\n@@ -15,11 +15,11 @@ merge_cmd () {\n \t\t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n \t\tfi\n \t\t;;\n-\tgvimdiff2|vimdiff2)\n+\t*vimdiff2)\n \t\t\"$merge_tool_path\" -f -d -c 'wincmd l' \\\n \t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n \t\t;;\n-\tgvimdiff3|vimdiff3)\n+\t*vimdiff3)\n \t\tif $base_present\n \t\tthen\n \t\t\t\"$merge_tool_path\" -f -d -c 'hid | hid | hid' \\\n@@ -34,10 +34,13 @@ merge_cmd () {\n \n translate_merge_tool_path() {\n \tcase \"$1\" in\n-\tgvimdiff|gvimdiff2|gvimdiff3)\n+\tnvimdiff*)\n+\t\techo nvim\n+\t\t;;\n+\tgvimdiff*)\n \t\techo gvim\n \t\t;;\n-\tvimdiff|vimdiff2|vimdiff3)\n+\tvimdiff*)\n \t\techo vim\n \t\t;;\n \tesac\n@@ -48,7 +51,7 @@ exit_code_trustable () {\n }\n \n list_tool_variants () {\n-\tfor prefix in '' g; do\n+\tfor prefix in '' g n; do\n \t\tfor suffix in '' 2 3; do\n \t\t\techo \"${prefix}vimdiff${suffix}\"\n \t\tdone\n-- \n2.28.0\n\n"}]}