run_diff.sh shellcheck fixes

* Replace backticks with $()
* Double-quote filenames that might conceivably contain troublesome special chars (*, space etc)
This commit is contained in:
Chris Smowton 2017-09-06 11:06:28 +01:00
parent dce6ae141a
commit 389221ebee
1 changed files with 13 additions and 13 deletions

View File

@ -2,8 +2,8 @@
set -e
script_folder=`dirname $0`
absolute_repository_root=`git rev-parse --show-toplevel`
script_folder=$(dirname "$0")
absolute_repository_root=$(git rev-parse --show-toplevel)
mode=$1
modes="CPPLINT | DOXYGEN"
@ -16,7 +16,7 @@ then
exit 1
fi
if ! [[ -e $script_folder/filter_by_lines.py ]]
if ! [[ -e ${script_folder}/filter_by_lines.py ]]
then
echo "Filter script could not be found in the $script_folder directory"
echo "Ensure filter_by_lines.py is inside the $script_folder directory then run again"
@ -31,13 +31,13 @@ then
exit 1
fi
if ! [[ -e $script_folder/cpplint.py ]]
if ! [[ -e "${script_folder}/cpplint.py" ]]
then
echo "Lint script could not be found in the $script_folder directory"
echo "Ensure cpplint.py is inside the $script_folder directory then run again"
exit 1
else
cmd='$script_folder/cpplint.py $file 2>&1 >/dev/null'
cmd='${script_folder}/cpplint.py $file 2>&1 >/dev/null'
fi
elif [[ "$mode" == "DOXYGEN" ]]
then
@ -78,26 +78,26 @@ else
git_merge_base_end="HEAD"
fi
git_start=`git merge-base $git_start $git_merge_base_end`
git_start=$(git merge-base $git_start $git_merge_base_end)
cleanup()
{
rm -f $diff_file $added_lines_file
rm -f "$diff_file" "$added_lines_file"
}
trap cleanup EXIT
diff_file=`mktemp`
added_lines_file=`mktemp`
diff_file=$(mktemp)
added_lines_file=$(mktemp)
# Pass the output through iconv to remove any invalid UTF-8 (diff_to_added_lines.py will die otherwise)
git diff $git_start $git_end | iconv -t utf-8 -c > $diff_file
git diff $git_start $git_end | iconv -t utf-8 -c > "$diff_file"
# Get the list of files that have changed, that end with lintable extensions
diff_files=`git diff --name-only $git_start $git_end | grep "\.\(\(cpp\)\|\(hh\)\|\(cc\)\|h\)$" || true`
diff_files=$(git diff --name-only $git_start $git_end | grep "\.\(\(cpp\)\|\(hh\)\|\(cc\)\|h\)$" || true)
$script_folder/diff_to_added_lines.py $diff_file $absolute_repository_root > $added_lines_file
"${script_folder}/diff_to_added_lines.py" "$diff_file" "$absolute_repository_root" > "$added_lines_file"
for file in $diff_files; do
file=$absolute_repository_root/$file
@ -109,7 +109,7 @@ for file in $diff_files; do
# Run the linting script and filter:
# The errors from the linter go to STDERR so must be redirected to STDOUT
result=`eval $cmd | $script_folder/filter_by_diff.py $file $added_lines_file $absolute_repository_root`
result=$(eval $cmd | "${script_folder}/filter_by_lines.py" "$file" "$added_lines_file" "$absolute_repository_root")
# Providing some errors were relevant we print them out
if [ "$result" ]