Skip to content

Commit 3865a7e

Browse files
sunshinecogitster
authored andcommitted
chainlint.sed: tolerate harmless ";" at end of last line in block
chainlint.sed flags ";" when used as a command terminator since it breaks the &&-chain, thus can allow failures to go undetected. However, when a command terminated by ";" is the last command in the body of a compound statement, such as `command-2` in: if test $# -gt 1 then command-1 && command-2; fi then the ";" is harmless and the exit code from `command-2` is passed through untouched and becomes the exit code of the compound statement, as if the ";" was not present. Therefore, tolerate a trailing ";" in this position rather than complaining about broken &&-chain. Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fbd992b commit 3865a7e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

t/chainlint.sed

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@
4747
# "?!AMP?!" violation is removed from the "bar" line (retrieved from the "hold"
4848
# area) since the final statement of a subshell must not end with "&&". The
4949
# final line of a subshell may still break the &&-chain by using ";" internally
50-
# to chain commands together rather than "&&", so "?!SEMI?!" is never removed
51-
# from a line (even though "?!AMP?!" might be).
50+
# to chain commands together rather than "&&", so "?!SEMI?!" is not removed
51+
# from such a line; however, if the line ends with "?!SEMI?!", then the ";" is
52+
# harmless and the annotation is removed.
5253
#
5354
# Care is taken to recognize the last _statement_ of a multi-line subshell, not
5455
# necessarily the last textual _line_ within the subshell, since &&-chaining
@@ -303,15 +304,15 @@ bcase
303304
# that line legitimately lacks "&&"
304305
:else
305306
x
306-
s/ ?!AMP?!$//
307+
s/\( ?!SEMI?!\)* ?!AMP?!$//
307308
x
308309
bcont
309310

310311
# found "done" closing for-loop or while-loop, or "fi" closing if-then -- drop
311312
# "suspect" from final contained line since that line legitimately lacks "&&"
312313
:done
313314
x
314-
s/ ?!AMP?!$//
315+
s/\( ?!SEMI?!\)* ?!AMP?!$//
315316
x
316317
# is 'done' or 'fi' cuddled with ")" to close subshell?
317318
/done.*)/bclose
@@ -354,7 +355,7 @@ bblock
354355
# since that line legitimately lacks "&&" and exit subshell loop
355356
:clssolo
356357
x
357-
s/ ?!AMP?!$//
358+
s/\( ?!SEMI?!\)* ?!AMP?!$//
358359
p
359360
x
360361
s/^/>/

t/chainlint/semicolon.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
cat foo; ?!SEMI?! echo bar
1212
>) &&
1313
(
14-
foo; ?!SEMI?!
14+
foo;
1515
>) &&
1616
(
1717
cd foo &&
1818
for i in a b c; do
19-
echo; ?!SEMI?!
19+
echo;
2020
> done)

0 commit comments

Comments
 (0)