Expand the t/check-non-portable-shell.pl checks to complain about the
use of "-a" and "-o" to the "test" shell built-in to to mean "and" and
"or", as opposed to using two "test" invocations with "&&" or "||".
There aren't any portability issues with using that construct that I
know of, but since Junio expressed a dislike of it in [1] and we've
currently got no such constructs let's add it to the lint checking. I
had various in-flight and WIP patches that used this construct.
1. https://lore.kernel.org/git/xmqqa6qkb5fi.fsf@gitster.g/ (local)
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/check-non-portable-shell.pl | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/t/check-non-portable-shell.pl b/t/check-non-portable-shell.pl
index fd3303552be..a5367346255 100755
--- a/t/check-non-portable-shell.pl
+++ b/t/check-non-portable-shell.pl
@@ -35,6 +35,7 @@ sub err {
next if $line =~ s/\\$//;
$_ = $line;
+ # Portability issues
/\bcp\s+-a/ and err 'cp -a is not portable';
/\bsed\s+-[^efn]\s+/ and err 'sed option not portable (use only -n, -e, -f)';
/\becho\s+-[neE]/ and err 'echo with option is not portable (use printf)';@@ -48,6 +49,9 @@ sub err {
/\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (use FOO=bar && export FOO)';
/^\s*([A-Z0-9_]+=(\w*|(["']).*?\3)\s+)+(\w+)/ and exists($func{$4}) and
err '"FOO=bar shell_func" assignment extends beyond "shell_func"';
+ # Coding style preferences
+ /\btest\s+-[a-z]\s+.*?\s+-a\s+/ and err '"test A && test B" preferred to "test A -a B"';
+ /\btest\s+-[a-z]\s+.*?\s+-o\s+/ and err '"test A || test B" preferred to "test A -o B"';
$line = '';
# this resets our $. for each file
close ARGV if eof;--
2.31.1.634.gb41287a30b0