[v2] devtools: check for supported git version

Message ID 20221025101512.3190439-1-alialnu@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] devtools: check for supported git version |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS

Commit Message

Ali Alnubani Oct. 25, 2022, 10:15 a.m. UTC
  The script devtools/parse-flow-support.sh uses the git-grep
option (-o, --only-matching), which is only supported from
git version 2.19 and onwards.[1]

The script now exits early providing a clear message to the user
about the required git version instead of showing the following
error messages multiple times:
  error: unknown switch `o'
  usage: git grep [<options>] [-e] <pattern> [<rev>...] [[--] <path>...]
  [..]

[1] https://github.com/git/git/blob/v2.19.0/Documentation/RelNotes/2.19.0.txt

Signed-off-by: Ali Alnubani <alialnu@nvidia.com>
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
Changes in v2:
- Refer to filename by $0 (Suggested by David Marchand).

 devtools/parse-flow-support.sh | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

David Marchand Oct. 26, 2022, 6:24 a.m. UTC | #1
On Tue, Oct 25, 2022 at 12:15 PM Ali Alnubani <alialnu@nvidia.com> wrote:
>
> The script devtools/parse-flow-support.sh uses the git-grep
> option (-o, --only-matching), which is only supported from
> git version 2.19 and onwards.[1]
>
> The script now exits early providing a clear message to the user
> about the required git version instead of showing the following
> error messages multiple times:
>   error: unknown switch `o'
>   usage: git grep [<options>] [-e] <pattern> [<rev>...] [[--] <path>...]
>   [..]
>
> [1] https://github.com/git/git/blob/v2.19.0/Documentation/RelNotes/2.19.0.txt
>
> Signed-off-by: Ali Alnubani <alialnu@nvidia.com>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>

I don't have a "non working" git, but the patch lgtm.

Acked-by: David Marchand <david.marchand@redhat.com>
  
Ferruh Yigit Oct. 26, 2022, 7:52 a.m. UTC | #2
On 10/26/2022 7:24 AM, David Marchand wrote:
> On Tue, Oct 25, 2022 at 12:15 PM Ali Alnubani <alialnu@nvidia.com> wrote:
>>
>> The script devtools/parse-flow-support.sh uses the git-grep
>> option (-o, --only-matching), which is only supported from
>> git version 2.19 and onwards.[1]
>>
>> The script now exits early providing a clear message to the user
>> about the required git version instead of showing the following
>> error messages multiple times:
>>    error: unknown switch `o'
>>    usage: git grep [<options>] [-e] <pattern> [<rev>...] [[--] <path>...]
>>    [..]
>>
>> [1] https://github.com/git/git/blob/v2.19.0/Documentation/RelNotes/2.19.0.txt
>>
>> Signed-off-by: Ali Alnubani <alialnu@nvidia.com>
>> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> 
> I don't have a "non working" git, but the patch lgtm.
> 
> Acked-by: David Marchand <david.marchand@redhat.com>
> 

+Chaoyong,

He had observed the problem, perhaps he can help to test.
  
Chaoyong He Oct. 26, 2022, 8:34 a.m. UTC | #3
> On 10/26/2022 7:24 AM, David Marchand wrote:
> > On Tue, Oct 25, 2022 at 12:15 PM Ali Alnubani <alialnu@nvidia.com> wrote:
> >>
> >> The script devtools/parse-flow-support.sh uses the git-grep option
> >> (-o, --only-matching), which is only supported from git version 2.19
> >> and onwards.[1]
> >>
> >> The script now exits early providing a clear message to the user
> >> about the required git version instead of showing the following error
> >> messages multiple times:
> >>    error: unknown switch `o'
> >>    usage: git grep [<options>] [-e] <pattern> [<rev>...] [[--] <path>...]
> >>    [..]
> >>
> >> [1]
> >> https://github.com/git/git/blob/v2.19.0/Documentation/RelNotes/2.19.0
> >> .txt
> >>
> >> Signed-off-by: Ali Alnubani <alialnu@nvidia.com>
> >> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> >
> > I don't have a "non working" git, but the patch lgtm.
> >
> > Acked-by: David Marchand <david.marchand@redhat.com>
> >
> 
> +Chaoyong,
> 
> He had observed the problem, perhaps he can help to test.

I test in my host, it does work.

$ git --version
git version 2.18.5

Before this patch:
$ ./devtools/check-doc-vs-code.sh
error: unknown switch `o'
usage: git grep [<options>] [-e] <pattern> [<rev>...] [[--] <path>...]
    --cached              search in index instead of in the work tree
    ...
repeat many times.

After this patch:
$ ./devtools/check-doc-vs-code.sh
git version >= 2.19 is required
  
Thomas Monjalon Oct. 31, 2022, 3:46 p.m. UTC | #4
26/10/2022 10:34, Chaoyong He:
> > On 10/26/2022 7:24 AM, David Marchand wrote:
> > > On Tue, Oct 25, 2022 at 12:15 PM Ali Alnubani <alialnu@nvidia.com> wrote:
> > >>
> > >> The script devtools/parse-flow-support.sh uses the git-grep option
> > >> (-o, --only-matching), which is only supported from git version 2.19
> > >> and onwards.[1]
> > >>
> > >> The script now exits early providing a clear message to the user
> > >> about the required git version instead of showing the following error
> > >> messages multiple times:
> > >>    error: unknown switch `o'
> > >>    usage: git grep [<options>] [-e] <pattern> [<rev>...] [[--] <path>...]
> > >>    [..]
> > >>
> > >> [1]
> > >> https://github.com/git/git/blob/v2.19.0/Documentation/RelNotes/2.19.0
> > >> .txt
> > >>
> > >> Signed-off-by: Ali Alnubani <alialnu@nvidia.com>
> > >> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > >
> > > I don't have a "non working" git, but the patch lgtm.
> > >
> > > Acked-by: David Marchand <david.marchand@redhat.com>
> > >
> > 
> > +Chaoyong,
> > 
> > He had observed the problem, perhaps he can help to test.
> 
> I test in my host, it does work.
> 
> $ git --version
> git version 2.18.5
> 
> Before this patch:
> $ ./devtools/check-doc-vs-code.sh
> error: unknown switch `o'
> usage: git grep [<options>] [-e] <pattern> [<rev>...] [[--] <path>...]
>     --cached              search in index instead of in the work tree
>     ...
> repeat many times.
> 
> After this patch:
> $ ./devtools/check-doc-vs-code.sh
> git version >= 2.19 is required

Applied, thanks.
  

Patch

diff --git a/devtools/parse-flow-support.sh b/devtools/parse-flow-support.sh
index 63c0b20e23..9811c7881c 100755
--- a/devtools/parse-flow-support.sh
+++ b/devtools/parse-flow-support.sh
@@ -13,6 +13,12 @@  if [ -z "$dir" ]; then
 	exit 1
 fi
 
+# test git-grep for -o (--only-matching) option
+if ! git grep -qo git -- $0 >/dev/null 2>&1; then
+	echo "git version >= 2.19 is required" >&2
+	exit 1
+fi
+
 # sorting order
 export LC_COLLATE=C