如何防止 `git difftool` 调用另一个 `vimdiff`?
How to prevent `git difftool` from calling another `vimdiff`?
我已将 git
配置(如下所示)以将 vimdiff
用作 difftool
,并在我调用 :qa
时立即比较另一对文件而不提示。这很棒。唯一的问题是有时许多文件存在差异。如何防止 git
来自 运行 另一个 vimdiff
实例并继续 diffs 队列?
git config --global diff.tool vimdiff
git config --global difftool.prompt false
git config --global alias.d difftool
我尝试使用非零错误代码 (:cq
) 退出 vim
,但没有帮助。
如果答案对 vim
和 nvim
都有效,那就太棒了。
我在不同的堆栈上得到了解决方案:
git config --global difftool.trustExitCode true
git config --global mergetool.trustExitCode true
然后退出 :cq
如@VonC 所述,也适用于 nvim
。
请注意,您不仅可以将 mergetool.trustExitCode true
应用到 vimdiff
,还可以将 nvimdiff
应用。
随着 Git 2.29(2020 年第 4 季度),基于 vim
变体的“git mergetool
"(man) 的现有后端已经重构,然后支持” nvim
”已添加。
参见 commit 1186897, commit 83bbf9b (29 Jul 2020) by pudinha (pudinha
)。
(由 Junio C Hamano -- gitster
-- in commit 873fa13 合并,2020 年 8 月 17 日)
mergetools
: add support for nvimdiff (neovim) family
Signed-off-by: pudinha
修复在 mergetool
中的 nvimdiff
支持添加到 Git 2.30(2021 年第一季度)时引入的回归问题。
参见 commit 12026f4, commit 6bc9082 (11 Nov 2020) by Johannes Schindelin (dscho
)。
(由 Junio C Hamano -- gitster
-- in commit d203add 合并,2020 年 11 月 21 日)
mergetool
: avoid letting list_tool_variants
break user-defined setups
Signed-off-by: Johannes Schindelin
In 83bbf9b92ea8 ("mergetool--lib
: improve support for vimdiff-style tool variants", 2020-07-29, Git v2.29.0-rc0 -- merge listed in batch #8), we introduced a list_tool_variants
function in the spirit of Postel's Law: be lenient in what you accept as input. In this particular instance, we wanted to allow not only bc
but also bc3
as name for the Beyond Compare tool.
However, what this patch overlooked is that it is totally allowed for users to override the defaults in mergetools/
.
But now that we strip off trailing digits, the name that the user gave the tool might not actually be in the list produced by list_tool_variants
.
So let's do the same as for the diff_cmd
and the merge_cmd
: override it with the trivial version in case a user-defined setup was detected.
Git 2.30.1(2021 年第一季度)修复了 2.29 回归,其中“git mergetool --tool-help
"(man) 未能列出所有可用工具。
参见 commit 80f5a16 (07 Jan 2021) by Philippe Blain (phil-blain
)。
(由 Junio C Hamano -- gitster
-- in commit 073552d 合并,2021 年 1 月 15 日)
mergetool--lib
: fix '--tool-help
' to correctly show available tools
Reported-by: Philippe Blain
Based-on-patch-by: Johannes Sixt
Signed-off-by: Philippe Blain
Commit 83bbf9b ("mergetool--lib
: improve support for vimdiff-style tool variants", 2020-07-29, Git v2.29.0-rc0 -- merge listed in batch #8) introduced a regression in the output of git mergetool --tool-help
(man) and git difftool --tool-help
(man) [1].
In function 'show_tool_names
' in git-mergetool--lib.sh
, we loop over the supported mergetools
and their variants and accumulate them in the variable 'variants
', separating them with a literal '\n
'.
The code then uses 'echo $variants
' to turn these '\n
' into newlines, but this behaviour is not portable, it just happens to work in some shells, like dash(1)'s 'echo' builtin.
For shells in which 'echo
' does not turn '\n
' into newlines, the end result is that the only tools that are shown are the existing variants (except the last variant alphabetically), since the variants are separated by actual newlines in '$variants
' because of the several 'echo
' calls in mergetools/{bc,vimdiff}::list_tool_variants
.
Fix this bug by embedding an actual line feed into variants
in show_tool_names()
.
While at it, replace sort
| uniq
by sort -u
.
To prevent future regressions, add a simple test that checks that a few known tools are correctly shown (let's avoid counting the total number of tools to lessen the maintenance burden when new tools are added or if '--tool-help
' learns additional logic, like hiding tools depending on the current platform).
[1] https://lore.kernel.org/git/CADtb9DyozjgAsdFYL8fFBEWmq7iz4=prZYVUdH9W-J5CKVS4OA@mail.gmail.com/
我已将 git
配置(如下所示)以将 vimdiff
用作 difftool
,并在我调用 :qa
时立即比较另一对文件而不提示。这很棒。唯一的问题是有时许多文件存在差异。如何防止 git
来自 运行 另一个 vimdiff
实例并继续 diffs 队列?
git config --global diff.tool vimdiff
git config --global difftool.prompt false
git config --global alias.d difftool
我尝试使用非零错误代码 (:cq
) 退出 vim
,但没有帮助。
如果答案对 vim
和 nvim
都有效,那就太棒了。
我在不同的堆栈上得到了解决方案:
git config --global difftool.trustExitCode true
git config --global mergetool.trustExitCode true
然后退出 :cq
如@VonC 所述,也适用于 nvim
。
请注意,您不仅可以将 mergetool.trustExitCode true
应用到 vimdiff
,还可以将 nvimdiff
应用。
随着 Git 2.29(2020 年第 4 季度),基于 vim
变体的“git mergetool
"(man) 的现有后端已经重构,然后支持” nvim
”已添加。
参见 commit 1186897, commit 83bbf9b (29 Jul 2020) by pudinha (pudinha
)。
(由 Junio C Hamano -- gitster
-- in commit 873fa13 合并,2020 年 8 月 17 日)
mergetools
: add support for nvimdiff (neovim) familySigned-off-by: pudinha
修复在 mergetool
中的 nvimdiff
支持添加到 Git 2.30(2021 年第一季度)时引入的回归问题。
参见 commit 12026f4, commit 6bc9082 (11 Nov 2020) by Johannes Schindelin (dscho
)。
(由 Junio C Hamano -- gitster
-- in commit d203add 合并,2020 年 11 月 21 日)
mergetool
: avoid lettinglist_tool_variants
break user-defined setupsSigned-off-by: Johannes Schindelin
In 83bbf9b92ea8 ("
mergetool--lib
: improve support for vimdiff-style tool variants", 2020-07-29, Git v2.29.0-rc0 -- merge listed in batch #8), we introduced alist_tool_variants
function in the spirit of Postel's Law: be lenient in what you accept as input. In this particular instance, we wanted to allow not onlybc
but alsobc3
as name for the Beyond Compare tool.However, what this patch overlooked is that it is totally allowed for users to override the defaults in
mergetools/
.
But now that we strip off trailing digits, the name that the user gave the tool might not actually be in the list produced bylist_tool_variants
.So let's do the same as for the
diff_cmd
and themerge_cmd
: override it with the trivial version in case a user-defined setup was detected.
Git 2.30.1(2021 年第一季度)修复了 2.29 回归,其中“git mergetool --tool-help
"(man) 未能列出所有可用工具。
参见 commit 80f5a16 (07 Jan 2021) by Philippe Blain (phil-blain
)。
(由 Junio C Hamano -- gitster
-- in commit 073552d 合并,2021 年 1 月 15 日)
mergetool--lib
: fix '--tool-help
' to correctly show available toolsReported-by: Philippe Blain
Based-on-patch-by: Johannes Sixt
Signed-off-by: Philippe Blain
Commit 83bbf9b ("
mergetool--lib
: improve support for vimdiff-style tool variants", 2020-07-29, Git v2.29.0-rc0 -- merge listed in batch #8) introduced a regression in the output ofgit mergetool --tool-help
(man) andgit difftool --tool-help
(man) [1].In function '
show_tool_names
' ingit-mergetool--lib.sh
, we loop over the supportedmergetools
and their variants and accumulate them in the variable 'variants
', separating them with a literal '\n
'.The code then uses '
echo $variants
' to turn these '\n
' into newlines, but this behaviour is not portable, it just happens to work in some shells, like dash(1)'s 'echo' builtin.For shells in which '
echo
' does not turn '\n
' into newlines, the end result is that the only tools that are shown are the existing variants (except the last variant alphabetically), since the variants are separated by actual newlines in '$variants
' because of the several 'echo
' calls inmergetools/{bc,vimdiff}::list_tool_variants
.Fix this bug by embedding an actual line feed into
variants
inshow_tool_names()
.
While at it, replacesort
|uniq
bysort -u
.To prevent future regressions, add a simple test that checks that a few known tools are correctly shown (let's avoid counting the total number of tools to lessen the maintenance burden when new tools are added or if '
--tool-help
' learns additional logic, like hiding tools depending on the current platform).[1] https://lore.kernel.org/git/CADtb9DyozjgAsdFYL8fFBEWmq7iz4=prZYVUdH9W-J5CKVS4OA@mail.gmail.com/