# [PATCH] test-lib: try harder to ensure a working jgit

11 messages from 2019-05-14 to 2019-05-15. Participants: Todd Zullinger, brian m. carlson, Jonathan Nieder, Ævar Arnfjörð Bjarmason, Jeff King, Junio C Hamano.
Thread: https://gitlist.dev/t/51087

## Todd Zullinger, 2019-05-14 02:05

Subject: [PATCH] test-lib: try harder to ensure a working jgit
Message-ID: <20190514020520.GI3654@pobox.com>
URL: https://gitlist.dev/e/20190514020520.GI3654%40pobox.com

```
The JGIT prereq uses 'type jgit' to determine whether jgit is present.
While this should be sufficient, if the jgit found is broken we'll waste
time running tests which fail due to no fault of our own.

Use 'jgit --version' instead, to catch some badly broken jgit
installations.

Signed-off-by: Todd Zullinger <tmz@pobox.com>
---
I ran into such a broken jgit on Fedora >= 30¹.  This is clearly a
problem in the Fedora jgit package which will hopefully be resolved
soon.  But it may be good to avoid wasting time debugging tests which
fail due to a broken tool outside of our control.

¹ https://bugzilla.redhat.com/1709624

 t/test-lib.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index 908ddb9c46..599fd70e14 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1522,7 +1522,7 @@ test_lazy_prereq NOT_ROOT '
 '
 
 test_lazy_prereq JGIT '
-	type jgit
+	jgit --version
 '
 
 # SANITY is about "can you correctly predict what the filesystem would
-- 
Todd

```

## brian m. carlson, 2019-05-14 02:14

Subject: Re: [PATCH] test-lib: try harder to ensure a working jgit
Message-ID: <20190514021419.GI7458@genre.crustytoothpaste.net>
URL: https://gitlist.dev/e/20190514021419.GI7458%40genre.crustytoothpaste.net
In-Reply-To: <20190514020520.GI3654@pobox.com>

```
On Mon, May 13, 2019 at 10:05:20PM -0400, Todd Zullinger wrote:
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 908ddb9c46..599fd70e14 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -1522,7 +1522,7 @@ test_lazy_prereq NOT_ROOT '
>  '
>  
>  test_lazy_prereq JGIT '
> -	type jgit
> +	jgit --version
>  '

I think this is an improvement, not only because of the reasons you
mentioned, but because we remove the use of "type", which is not
guaranteed to be present in a POSIX shell.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

```

## Jonathan Nieder, 2019-05-14 02:32

Subject: Re: [PATCH] test-lib: try harder to ensure a working jgit
Message-ID: <20190514023245.GB34155@google.com>
URL: https://gitlist.dev/e/20190514023245.GB34155%40google.com
In-Reply-To: <20190514020520.GI3654@pobox.com>

```
Todd Zullinger wrote:

> The JGIT prereq uses 'type jgit' to determine whether jgit is present.
> While this should be sufficient, if the jgit found is broken we'll waste
> time running tests which fail due to no fault of our own.
>
> Use 'jgit --version' instead, to catch some badly broken jgit
> installations.
>
> Signed-off-by: Todd Zullinger <tmz@pobox.com>
> ---
> I ran into such a broken jgit on Fedora >= 30¹.  This is clearly a
> problem in the Fedora jgit package which will hopefully be resolved
> soon.  But it may be good to avoid wasting time debugging tests which
> fail due to a broken tool outside of our control.
>
> ¹ https://bugzilla.redhat.com/1709624

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

It would be nice to describe that bug in the commit message, to save
readers some head scratching.

Thanks,
Jonathan

```

## Ævar Arnfjörð Bjarmason, 2019-05-14 08:09

Subject: Re: [PATCH] test-lib: try harder to ensure a working jgit
Message-ID: <87o945wj7w.fsf@evledraar.gmail.com>
URL: https://gitlist.dev/e/87o945wj7w.fsf%40evledraar.gmail.com
In-Reply-To: <20190514023245.GB34155@google.com>

```

On Tue, May 14 2019, Jonathan Nieder wrote:

> Todd Zullinger wrote:
>
>> The JGIT prereq uses 'type jgit' to determine whether jgit is present.
>> While this should be sufficient, if the jgit found is broken we'll waste
>> time running tests which fail due to no fault of our own.
>>
>> Use 'jgit --version' instead, to catch some badly broken jgit
>> installations.
>>
>> Signed-off-by: Todd Zullinger <tmz@pobox.com>
>> ---
>> I ran into such a broken jgit on Fedora >= 30¹.  This is clearly a
>> problem in the Fedora jgit package which will hopefully be resolved
>> soon.  But it may be good to avoid wasting time debugging tests which
>> fail due to a broken tool outside of our control.
>>
>> ¹ https://bugzilla.redhat.com/1709624
>
> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
>
> It would be nice to describe that bug in the commit message, to save
> readers some head scratching.

FWIW the jgit in Debian testing/unstable is similarly broken right now:

    $ apt policy jgit-cli
    jgit-cli:
      Installed: 3.7.1-6
      Candidate: 3.7.1-6
      Version table:
     *** 3.7.1-6 900
            900 http://ftp.nl.debian.org/debian testing/main amd64 Packages
            800 http://ftp.nl.debian.org/debian unstable/main amd64 Packages
            100 /var/lib/dpkg/status
         3.7.1-4 700
            700 http://ftp.nl.debian.org/debian stable/main amd64 Packages
    $ jgit --version; echo $?
    Error: A JNI error has occurred, please check your installation and try again
    Exception in thread "main" java.lang.NoClassDefFoundError: org/kohsuke/args4j/CmdLineException
            at java.lang.Class.getDeclaredMethods0(Native Method)
            at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
            at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
            at java.lang.Class.getMethod0(Class.java:3018)
            at java.lang.Class.getMethod(Class.java:1784)
            at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
            at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
    Caused by: java.lang.ClassNotFoundException: org.kohsuke.args4j.CmdLineException
            at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
            ... 7 more
    1

So rather than describe specific bugs on RedHat/Debian maybe just say:

    This guards against cases where jgit is present on the system, but
    will fail to run, e.g. because of some JRE issue, or missing Java
    dependencies. Seeing if it gets far enough to process the
    "--version" argument isn't perfect, but seems to be good enough in
    practice. It's also consistent with how we detect some other
    dependencies, see e.g. the CURL and UNZIP prerequisites.

```

## Jeff King, 2019-05-14 08:45

Subject: Re: [PATCH] test-lib: try harder to ensure a working jgit
Message-ID: <20190514084534.GA9567@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20190514084534.GA9567%40sigill.intra.peff.net
In-Reply-To: <20190514021419.GI7458@genre.crustytoothpaste.net>

```
On Tue, May 14, 2019 at 02:14:19AM +0000, brian m. carlson wrote:

> On Mon, May 13, 2019 at 10:05:20PM -0400, Todd Zullinger wrote:
> > diff --git a/t/test-lib.sh b/t/test-lib.sh
> > index 908ddb9c46..599fd70e14 100644
> > --- a/t/test-lib.sh
> > +++ b/t/test-lib.sh
> > @@ -1522,7 +1522,7 @@ test_lazy_prereq NOT_ROOT '
> >  '
> >  
> >  test_lazy_prereq JGIT '
> > -	type jgit
> > +	jgit --version
> >  '
> 
> I think this is an improvement, not only because of the reasons you
> mentioned, but because we remove the use of "type", which is not
> guaranteed to be present in a POSIX shell.

Isn't it? I have always treated it as the most-portable option for this
(compared to, say, `which`).  It is in POSIX as a utility (albeit marked
with XSI), which even says (in APPLICATION USAGE):

  Since type must be aware of the contents of the current shell
  execution environment (such as the lists of commands, functions, and
  built-ins processed by hash), it is always provided as a shell regular
  built-in.

All that said, I think Todd's patch makes perfect sense even without
wanting to avoid "type".

-Peff

```

## Junio C Hamano, 2019-05-15 00:52

Subject: Re: [PATCH] test-lib: try harder to ensure a working jgit
Message-ID: <xmqqzhno8rpa.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqqzhno8rpa.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <20190514084534.GA9567@sigill.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

> All that said, I think Todd's patch makes perfect sense even without
> wanting to avoid "type".

Same here.  t/lib-bash.sh seems to use "if type bash" to see if one
is available on $PATH; I've never felt the need to avoid "type".

```

## Todd Zullinger, 2019-05-15 01:12

Subject: Re: [PATCH] test-lib: try harder to ensure a working jgit
Message-ID: <20190515011217.GN3654@pobox.com>
URL: https://gitlist.dev/e/20190515011217.GN3654%40pobox.com
In-Reply-To: <20190514084534.GA9567@sigill.intra.peff.net>

```
Hi,

Jeff King wrote:
> On Tue, May 14, 2019 at 02:14:19AM +0000, brian m. carlson wrote:
> 
>> On Mon, May 13, 2019 at 10:05:20PM -0400, Todd Zullinger wrote:
>>> diff --git a/t/test-lib.sh b/t/test-lib.sh
>>> index 908ddb9c46..599fd70e14 100644
>>> --- a/t/test-lib.sh
>>> +++ b/t/test-lib.sh
>>> @@ -1522,7 +1522,7 @@ test_lazy_prereq NOT_ROOT '
>>>  '
>>>  
>>>  test_lazy_prereq JGIT '
>>> -	type jgit
>>> +	jgit --version
>>>  '
>> 
>> I think this is an improvement, not only because of the reasons you
>> mentioned, but because we remove the use of "type", which is not
>> guaranteed to be present in a POSIX shell.
>
> Isn't it?

I wondered the same thing, but I know I am not nearly as
familiar with the POSIX rules as any of you.

> I have always treated it as the most-portable option for this
> (compared to, say, `which`).  It is in POSIX as a utility (albeit marked
> with XSI), which even says (in APPLICATION USAGE):
> 
>   Since type must be aware of the contents of the current shell
>   execution environment (such as the lists of commands, functions, and
>   built-ins processed by hash), it is always provided as a shell regular
>   built-in.
> 
> All that said, I think Todd's patch makes perfect sense even without
> wanting to avoid "type".

Yeah, `which` surely isn't a portable option.  I presumed
`type` must be fairly widely available since it was in the
test suite since you added it way back in 212f2ffbf0 ("t:
add basic bitmap functionality tests", 2013-12-21).

I usually make use of `command -p -v $foo` in scripts that
need to be portable across systems.  But I don't have access
to many esoteric systems.

Based on Junio's follow-up, I think we can avoid adding
anything to the commit message about the use of `type` here.
That way no one will take it as a sign that we should remove
other uses of it just for conformance.  (I will send a
follow-up with an update based on Jonathan and Ævar's
comments.)

Thanks to all of you.

-- 
Todd

```

## Todd Zullinger, 2019-05-15 01:18

Subject: Re: [PATCH] test-lib: try harder to ensure a working jgit
Message-ID: <20190515011851.GP3654@pobox.com>
URL: https://gitlist.dev/e/20190515011851.GP3654%40pobox.com
In-Reply-To: <87o945wj7w.fsf@evledraar.gmail.com>

```
Hi,

Ævar Arnfjörð Bjarmason wrote:
> 
> On Tue, May 14 2019, Jonathan Nieder wrote:
> 
>> Todd Zullinger wrote:
>>
>>> The JGIT prereq uses 'type jgit' to determine whether jgit is present.
>>> While this should be sufficient, if the jgit found is broken we'll waste
>>> time running tests which fail due to no fault of our own.
>>>
>>> Use 'jgit --version' instead, to catch some badly broken jgit
>>> installations.
>>>
>>> Signed-off-by: Todd Zullinger <tmz@pobox.com>
>>> ---
>>> I ran into such a broken jgit on Fedora >= 30¹.  This is clearly a
>>> problem in the Fedora jgit package which will hopefully be resolved
>>> soon.  But it may be good to avoid wasting time debugging tests which
>>> fail due to a broken tool outside of our control.
>>>
>>> ¹ https://bugzilla.redhat.com/1709624
>>
>> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
>>
>> It would be nice to describe that bug in the commit message, to save
>> readers some head scratching.
> 
> FWIW the jgit in Debian testing/unstable is similarly broken right now:
[...]

Hah, small world. :)

> So rather than describe specific bugs on RedHat/Debian maybe just say:
> 
>     This guards against cases where jgit is present on the system, but
>     will fail to run, e.g. because of some JRE issue, or missing Java
>     dependencies. Seeing if it gets far enough to process the
>     "--version" argument isn't perfect, but seems to be good enough in
>     practice. It's also consistent with how we detect some other
>     dependencies, see e.g. the CURL and UNZIP prerequisites.

Well said.  I indeed avoided putting the detail into the
commit message because it was such a Fedora-specific bug.
I'll update the commit message to add more details though,
borrowing liberally from^W^W^Wperhaps stealing your
suggested wording.

Thanks!

-- 
Todd

```

## Todd Zullinger, 2019-05-15 01:36

Subject: [PATCH v2] test-lib: try harder to ensure a working jgit
Message-ID: <20190515013633.GQ3654@pobox.com>
URL: https://gitlist.dev/e/20190515013633.GQ3654%40pobox.com
In-Reply-To: <20190514020520.GI3654@pobox.com>

```
The JGIT prereq uses `type jgit` to determine whether jgit is present.
While this is usually sufficient, it won't help if the jgit found is
badly broken.  This wastes time running tests which fail due to no fault
of our own.

Use `jgit --version` instead, to guard against cases where jgit is
present on the system, but will fail to run, e.g. because of some JRE
issue, or missing Java dependencies.  Checking that it gets far enough
to process the '--version' argument isn't perfect, but seems to be good
enough in practice.  It's also consistent with how we detect some other
dependencies, see e.g. the CURL and UNZIP prerequisites.

Signed-off-by: Todd Zullinger <tmz@pobox.com>
---
As promised, I stole the second paragraph from Ævar nearly verbatim. :)

 t/test-lib.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index 908ddb9c46..599fd70e14 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1522,7 +1522,7 @@ test_lazy_prereq NOT_ROOT '
 '
 
 test_lazy_prereq JGIT '
-	type jgit
+	jgit --version
 '
 
 # SANITY is about "can you correctly predict what the filesystem would
-- 
Todd

```

## Junio C Hamano, 2019-05-15 02:13

Subject: Re: [PATCH] test-lib: try harder to ensure a working jgit
Message-ID: <xmqqtvdw79dh.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqqtvdw79dh.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <20190515011851.GP3654@pobox.com>

```
Todd Zullinger <tmz@pobox.com> writes:

>>     This guards against cases where jgit is present on the system, but
>>     will fail to run, e.g. because of some JRE issue, or missing Java
>>     dependencies. Seeing if it gets far enough to process the
>>     "--version" argument isn't perfect, but seems to be good enough in
>>     practice. It's also consistent with how we detect some other
>>     dependencies, see e.g. the CURL and UNZIP prerequisites.
>
> Well said.  I indeed avoided putting the detail into the
> commit message because it was such a Fedora-specific bug.
> I'll update the commit message to add more details though,
> borrowing liberally from^W^W^Wperhaps stealing your
> suggested wording.
>
> Thanks!

Thanks, all.

```

## brian m. carlson, 2019-05-15 23:20

Subject: Re: [PATCH] test-lib: try harder to ensure a working jgit
Message-ID: <20190515232032.GN7458@genre.crustytoothpaste.net>
URL: https://gitlist.dev/e/20190515232032.GN7458%40genre.crustytoothpaste.net
In-Reply-To: <20190514084534.GA9567@sigill.intra.peff.net>

```
On Tue, May 14, 2019 at 04:45:34AM -0400, Jeff King wrote:
> On Tue, May 14, 2019 at 02:14:19AM +0000, brian m. carlson wrote:
> > I think this is an improvement, not only because of the reasons you
> > mentioned, but because we remove the use of "type", which is not
> > guaranteed to be present in a POSIX shell.
> 
> Isn't it? I have always treated it as the most-portable option for this
> (compared to, say, `which`).  It is in POSIX as a utility (albeit marked
> with XSI), which even says (in APPLICATION USAGE):
> 
>   Since type must be aware of the contents of the current shell
>   execution environment (such as the lists of commands, functions, and
>   built-ins processed by hash), it is always provided as a shell regular
>   built-in.

It's an XSI extension, while "command -v" is not. "type" may be more
common for historical reasons, but if you have systems that don't
implement XSI, "command -v" is the way to go.

I suppose this doesn't matter unless we have people try to build with
Debian's posh package, which only implements the minimum requirements
for a Debian /bin/sh (which don't include XSI extensions, but do include
local).

> All that said, I think Todd's patch makes perfect sense even without
> wanting to avoid "type".

I agree this is an improvement either way.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

```
