Skip to contentSkip to conversation

devtools: check for supported git version

PATCH Superseded Ali Alnubani 5 participants 7 messages Oct 24, 2022 – Oct 31, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 devtools: check for supported git version

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

---
 devtools/parse-flow-support.sh | 6 ++++++
 1 file changed, 6 insertions(+)
devtools/parse-flow-support.sh +6 -0
index 63c0b20e23..9c322249da 100755
@@ -13,6 +13,12 @@ if [ -z "$dir" ]; then
 	exit 1
 fi
 
+# test git-grep for -o (--only-matching) option
+if ! git grep -qo git -- devtools/parse-flow-support.sh >/dev/null 2>&1; then
+	echo "git version >= 2.19 is required" >&2
+	exit 1
+fi
+
 # sorting order
 export LC_COLLATE=C
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 25 lines · Ali Alnubani

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

---
 devtools/parse-flow-support.sh | 6 ++++++
 1 file changed, 6 insertions(+)
devtools/parse-flow-support.sh +0 -0
index 63c0b20e23..9c322249da 100755

devtools/parse-flow-support.sh if [ -z "$dir" ]; then · line 17

Quoted 5 lines
devtools/parse-flow-support.sh +2 -0
@@ -13,6 +13,12 @@ if [ -z "$dir" ]; then
        exit 1
 fi
 
+# test git-grep for -o (--only-matching) option
+if ! git grep -qo git -- devtools/parse-flow-support.sh >/dev/null 2>&1; then

Would it work with $0, to refer to the script itself?

Quoted 10 lines
devtools/parse-flow-support.sh +4 -1
+       echo "git version >= 2.19 is required" >&2
+       exit 1
+fi
+
 # sorting order
 export LC_COLLATE=C
 
--

2.25.1

Signature · 1 line
David Marchand
#2 lore raw

PATCH v2 1/1 devtools: check for supported git version

In reply to Ali Alnubani

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

---
Changes in v2:
- Refer to filename by $0 (Suggested by David Marchand).

 devtools/parse-flow-support.sh | 6 ++++++
 1 file changed, 6 insertions(+)
devtools/parse-flow-support.sh +6 -0
index 63c0b20e23..9811c7881c 100755
@@ -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
 
Signature · 1 line
2.25.1
Acked-by on v2 1/1
#3 lore raw
Quoted 12 lines · Ali Alnubani

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>...] [..]

Quoted 4 lines

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

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

Signature · 1 line
David Marchand
#4 lore raw
Quoted 13 lines · David Marchand
Quoted 12 lines · Ali Alnubani

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>...]
   [..]
Quoted 9 lines
Quoted 4 lines

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

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

+Chaoyong,

He had observed the problem, perhaps he can help to test.

#5 lore raw
Quoted 21 lines · David Marchand
Quoted 20 lines · Ali Alnubani
Quoted 18 lines

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

Quoted 8 lines
Quoted 4 lines

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

+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
#6 lore raw

26/10/2022 10:34, Chaoyong He:

Quoted 43 lines
Quoted 21 lines · David Marchand
Quoted 20 lines · Ali Alnubani
Quoted 18 lines

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

Quoted 8 lines
Quoted 4 lines

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

+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.
Quoted 3 lines

After this patch:

$ ./devtools/check-doc-vs-code.sh
git version >= 2.19 is required

Applied, thanks.