You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: rev_news/drafts/edition-116.md
+67-2
Original file line number
Diff line number
Diff line change
@@ -25,10 +25,75 @@ This edition covers what happened during the months of September 2024 and Octobe
25
25
### Reviews
26
26
-->
27
27
28
-
<!---
29
28
### Support
30
-
-->
31
29
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]/)
0 commit comments