git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Philippe Blain <levraiphilippeblain@gmail.com>
To: "Junio C Hamano" <gitster@pobox.com>,
	"SZEDER Gábor" <szeder.dev@gmail.com>
Cc: "Philippe Blain via GitGitGadget" <gitgitgadget@gmail.com>,
	git@vger.kernel.org, "Johannes Sixt" <j6t@kdbg.org>,
	"Felipe Contreras" <felipe.contreras@gmail.com>,
	pudinha <rogi@skylittlesystem.org>, "René Scharfe" <l.s.r@web.de>
Subject: Re: [PATCH v2] mergetool--lib: fix '--tool-help' to correctly show available tools
Date: Wed, 6 Jan 2021 17:59:10 -0500	[thread overview]
Message-ID: <3664fffc-c2a0-62d6-298b-8e95f3c58a68@gmail.com> (raw)
In-Reply-To: <xmqq5z49rclc.fsf@gitster.c.googlers.com>

Hi Junio,

Le 2021-01-06 à 16:15, Junio C Hamano a écrit :
> SZEDER Gábor <szeder.dev@gmail.com> writes:
> 
>> On Mon, Dec 28, 2020 at 07:41:44PM +0000, Philippe Blain via GitGitGadget wrote:
>>> To prevent future regressions, add a simple test that counts the number
>>> of tools shown by 'git mergetool --tool-help', irrespective of their
>>> installed status, by making use of the fact that mergetools are listed
>>> by 'git mergetool --tool-help' on lines starting with tabs. Prefix the
>>> `git config` commands used at the beginning of the test to remove the
>>> fake tools used by the previous test with 'test_might_fail' so that the
>>> test can be run independantly of the previous test without failing.
>>
>>> diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
>>> index 70afdd06fa7..ebd3af139e5 100755
>>> --- a/t/t7610-mergetool.sh
>>> +++ b/t/t7610-mergetool.sh
>>> @@ -828,4 +828,14 @@ test_expect_success 'mergetool -Oorder-file is honored' '
>>>   	test_cmp expect actual
>>>   '
>>>   
>>> +test_expect_success 'mergetool --tool-help shows all recognized tools' '
>>> +	# Remove fake tools added in previous tests
>>> +	test_might_fail git config --unset merge.tool &&
>>> +	test_might_fail git config --remove-section mergetool.mytool &&
>>> +	test_might_fail git config --remove-section mergetool.mybase &&
>>> +	git mergetool --tool-help >output &&
>>> +	grep "$(printf "\t")" output >mergetools &&
>>> +	test_line_count = 30 mergetools
>>> +'
>>
>> This new test fails when the topic 'pb/mergetool-tool-help-fix' is
>> built and tested in isolation, because 'git mergetool --tool-help'
>> lists only 29 tools instead of the expected 30.  The reason is that
>> 'pb/mergetool-tool-help-fix' doesn't include commit 6bc9082c0f
>> (mergetools/bc: add `bc4` to the alias list for Beyond Compare,
>> 2020-11-11), which added that 30th tool (and is already part of
>> v2.30.0).
>>
>> It also makes me wonder whether this is the right way to test this
>> fix, because we'll need to adjust this test case every time we add
>> support for a new merge tool (which arguably doesn't happen that
>> often, but since we are already at 30 it doesn't seem to be that rare
>> either).
> 
> Yes, that is a very good point.  Also I can imagine us allowing some
> tools to be excluded depending on a build/installation option and/or
> which platform you are on, so hardcoded 30 smells a bit too fragile
> as an approach for a project like ours.

As I said in my response to Gabor [1], this was a simple attempt at
preventing a future breakage. I agree that it could be improved, but
I'm not sure how without actually re-implementing the code of
'git mergetool --tool-help' in the test itself, especially if more
logic is added as you say for eg. hiding some tools depending
on platform/installation options.

> 
> What was the symptom before the fix?  Is it just missing only some
> tools among 30?  Was there some pattern in names of missing one and
> the ones that still got output?  Or was it more like "we see nothing
> shown"?
> 

The only tools that are shown are the variants, except the alphabetically last variant,
because as I wrote in the commit message,

For shells in which 'echo' does not turn '\n' into newlines, the end result is
that the only tools that are shown are those that are found and have variants,
since the variants are separated by actual newlines in '$variants' because of
the several 'echo' calls in mergetools/{bc,vimdiff}::list_tool_variants.

[Note: I should re-roll and remove "that are found" since that bit is not true).

For example, I get this with Bash 4.4.19 as /bin/sh on Ubuntu 18.04:

---
$ git mergetool --tool-help
'git mergetool --tool=<tool>' may be set to one of the following:
                 gvimdiff
                 gvimdiff2
                 gvimdiff3
                 vimdiff2
                 vimdiff3

The following tools are valid, but not currently available:
                 bc3
                 nvimdiff
                 nvimdiff2

Some of the tools listed above only work in a windowed
environment. If run in a terminal-only session, they will fail.
---

Note that 'vimdiff', 'nvimdiff3' (last variant for vimdiff),
'bc' and 'bc4' (last variant for bc) are absent, and
all other tools that have no variants are absent as well.

I was able to understand what was happening by running 'git mergetool'
with Bash tracing:

PATH=$(git --exec-path):$PATH \
PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' \
bash -x $(git --exec-path)/git-mergetool --tool-help

P.S.
I noticed that all tools are shown correctly on my Mac,
which has Bash 3.2.57 as /bin/sh. So behaviour of 'echo' regarding
'\n' depends on both the shell and its version (!)


[1] https://lore.kernel.org/git/11b3c261-14e6-0293-02a6-92bd1ea680d2@gmail.com/

  reply	other threads:[~2021-01-06 23:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-28 18:22 [PATCH] mergetool--lib: fix '--tool-help' to correctly show available tools Philippe Blain via GitGitGadget
2020-12-28 19:41 ` [PATCH v2] " Philippe Blain via GitGitGadget
2021-01-06 13:16   ` SZEDER Gábor
2021-01-06 13:34     ` Philippe Blain
2021-01-06 21:15     ` Junio C Hamano
2021-01-06 22:59       ` Philippe Blain [this message]
2021-01-06 23:06         ` Junio C Hamano
2021-01-07  0:32           ` Philippe Blain
2021-01-07  1:09   ` [PATCH v3] " Philippe Blain via GitGitGadget
2021-01-07 13:37     ` Philippe Blain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3664fffc-c2a0-62d6-298b-8e95f3c58a68@gmail.com \
    --to=levraiphilippeblain@gmail.com \
    --cc=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=l.s.r@web.de \
    --cc=rogi@skylittlesystem.org \
    --cc=szeder.dev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).