mirror of
https://github.com/git/git.git
synced 2024-10-31 06:17:56 +01:00
c7ce70ace9
Add the perl script "check-non-portable-shell.pl" to detect non-portable shell syntax. "echo -n" is an example of a shell command working on Linux, but not on Mac OS X. These shell commands are checked and reported as error: - "echo -n" (printf should be used) - "sed -i" (GNUism; use a temp file instead) - "declare" (bashism, often used with arrays) - "which" (unreliable exit status and output; use type instead) - "test a == b" (bashism for "test a = b") "make test-lint-shell-syntax" can be used to run only the check. Helped-By: Jeff King <peff@peff.net> Signed-off-by: Torsten Bögershausen <tboegi@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
27 lines
694 B
Perl
Executable file
27 lines
694 B
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
# Test t0000..t9999.sh for non portable shell scripts
|
|
# This script can be called with one or more filenames as parameters
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
my $exit_code=0;
|
|
|
|
sub err {
|
|
my $msg = shift;
|
|
print "$ARGV:$.: error: $msg: $_\n";
|
|
$exit_code = 1;
|
|
}
|
|
|
|
while (<>) {
|
|
chomp;
|
|
/^\s*sed\s+-i/ and err 'sed -i is not portable';
|
|
/^\s*echo\s+-n/ and err 'echo -n is not portable (please use printf)';
|
|
/^\s*declare\s+/ and err 'arrays/declare not portable';
|
|
/^\s*[^#]\s*which\s/ and err 'which is not portable (please use type)';
|
|
/test\s+[^=]*==/ and err '"test a == b" is not portable (please use =)';
|
|
# this resets our $. for each file
|
|
close ARGV if eof;
|
|
}
|
|
exit $exit_code;
|