Skip to content

Commit 768ab37

Browse files
committed
rn-116: add Git and 'grep -q' article
1 parent 40b3b51 commit 768ab37

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

Diff for: rev_news/drafts/edition-116.md

+67-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,75 @@ This edition covers what happened during the months of September 2024 and Octobe
2525
### Reviews
2626
-->
2727

28-
<!---
2928
### Support
30-
-->
3129

30+
* [fatal from submodule status --recursive when used with grep -q](https://lore.kernel.org/git/CAKDm0rNaHbzoiPg=DeuCoxzooNAsxw2BJfc0wg7fC_-=o9uJ7w@mail.gmail.com/)
31+
32+
Matt Liberty reported that when he tried using
33+
`git submodule status --recursive | grep -q "^+"` on a repo with
34+
a submodule, he got an error message like "fatal: failed to recurse
35+
into submodule XXX", where XXX is the name of the submodule.
36+
37+
He expected no error message, no output and a 0 exit code from the
38+
whole command line as it should have succeeded. He guessed that Git
39+
didn't like that `grep` when used with `-q` exits immediately
40+
(without printing anything) when there is a match.
41+
42+
Phillip Wood replied to Matt saying he assumed that `grep`'s exit
43+
broke the pipe between `git` and `grep`, so `git` received a
44+
'SIGPIPE' signal which killed it. Phillip suggested consuming the
45+
whole output from Git if the exit code from it was wanted.
46+
47+
Matt replied to Phillip that he was interested in the exit code from
48+
`grep` not from `git` and that Git shouldn't output any error when
49+
its output is connected to a pipe that gets broken, in the same way
50+
as the `yes` command, for example, doesn't output any error when
51+
piped to `grep -q y`.
52+
53+
Junio Hamano, the Git maintainer, also replied to Phillip's first
54+
message that the error Git emitted in such a case wasn't useful to
55+
the user.
56+
57+
Matt replied to Junio that he thought no error at all should be
58+
emitted as most Unix tools don't output any error.
59+
60+
Then Phillip replied to Matt's first reply to him. He asked if all
61+
Matt wanted was that `git submodule status` did not print any error
62+
message when it receives a SIGPIPE signal. Matt replied that he
63+
wanted both no error message and a 0 exit code from it.
64+
65+
Junio replied to Matt that it was reasonable to ask for no error
66+
message, but it should be OK if the exit code was related to the
67+
SIGPIPE message that the Git command received and that killed
68+
it. Junio used the example that even `yes` exited with code 130 when
69+
killed using the Control-C keys on a terminal.
70+
71+
The exit code associated with a signal is '128 + the signal number',
72+
for example as the Control-C keys send a SIGINT signal, which signal
73+
number is 2, processes killed this way should exit with code '128 + 2',
74+
so 130.
75+
76+
Eric Sunshine replied to Junio that it wasn't clear how the exit
77+
code from Git was important in the discussion as in the original
78+
command line, Git appears before the pipe, so its exit code might be
79+
lost.
80+
81+
Matt replied to Eric that the exit code mattered if the `pipefail`
82+
shell option was used.
83+
84+
Phillip replied to Matt suggesting he remap the exit code
85+
associated with SIGPIPE, which is 141 (128 + 13) to 0, if he was
86+
using `pipefail` but still wanted a 0 exit code. Phillip also gave
87+
an example shell function to help with that remapping, and sent
88+
[a first version of a patch](https://lore.kernel.org/git/[email protected]/)
89+
to fix the error message.
90+
91+
Junio reviewed that patch and found that it was unnecessarily
92+
including the "signal.h" system header.
93+
94+
Phillip fixed that issue in
95+
[version 2 of the patch](https://lore.kernel.org/git/[email protected]/)
96+
which was merged and part of Git v2.47.0.
3297

3398
## Developer Spotlight: Chandra Pratap
3499

0 commit comments

Comments
 (0)