fix: Improve Bash hygiene (#1056)

* fix: Improve Bash hygiene

* Update quoting to account for new bugs

* quotes

* fix: Remove extra shellcheck comment
This commit is contained in:
Edwin Kofler 2023-08-18 01:15:40 -07:00 committed by GitHub
parent 8af43892f6
commit 47e940272a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 26 deletions

View file

@ -22,9 +22,9 @@ done
if ! $LIST; then
FILE=$1
if test "$FILE" = ""; then
FILE=$(ls | grep -E 'authors|contributors' -i|head -n1)
if test "$FILE" = ""; then
if [ -z "$FILE" ]; then
FILE=$(find . -mindepth 1 -maxdepth 1 -iregex '.*\(authors\|contributors\).*' | head -n1)
if [ -z "$FILE" ]; then
FILE='AUTHORS'
fi
fi

View file

@ -280,7 +280,8 @@ commitList() {
for (( i=0; i<"${_tags_list_keys_length}"; i++ )); do
local __curr_tag="${tags_list_keys[$i]}"
local __prev_tag="${tags_list_keys[$i+1]:-null}"
local __curr_date="$(_valueForKeyFakeAssocArray "${__curr_tag}" "${tags_list[*]}")"
local __curr_date
__curr_date="$(_valueForKeyFakeAssocArray "${__curr_tag}" "${tags_list[*]}")"
__curr_date="${__curr_date##*=>}"
# output latest commits, up until the most-recent tag, these are all
@ -528,9 +529,10 @@ main() {
#
# generate changelog
#
local tmpfile="$(git_extra_mktemp)"
local changelog="$(_valueForKeyFakeAssocArray "output_file" "${option[*]}")"
local title_tag="$(_valueForKeyFakeAssocArray "title_tag" "${option[*]}")"
local tmpfile changelog title_tag
tmpfile="$(git_extra_mktemp)"
changelog="$(_valueForKeyFakeAssocArray "output_file" "${option[*]}")"
title_tag="$(_valueForKeyFakeAssocArray "title_tag" "${option[*]}")"
if [[ "$(_valueForKeyFakeAssocArray "list_style" "${option[*]}")" == true ]]; then
if [[ "$(_valueForKeyFakeAssocArray "list_all" "${option[*]}")" == true ]]; then
@ -549,7 +551,7 @@ main() {
fi
if [[ -z "$changelog" ]]; then
changelog="$(ls | grep -E 'change|history' -i | head -n1)"
changelog="$(find . -mindepth 1 -maxdepth 1 -iregex '.*\(change\|history\).*' | head -n1)"
if [[ -z "$changelog" ]]; then
changelog="History.md";
fi

View file

@ -87,7 +87,7 @@ do
do
printf "+"
done
printf "(%s)" $num
printf "(%s)" "$num"
else
for (( i = 0; i < num; i++ ))
do

View file

@ -20,7 +20,7 @@ cleanup() {
rm "$index"
exit 2
}
trap cleanup 2
trap cleanup INT
# Go back in history while parent commits are available.
echo "Trying to find a commit the patch applies to..."

View file

@ -80,7 +80,8 @@ function scp_and_stage
set_remote "$1"
shift
local refhead="$(git rev-parse --quiet --verify "$1")"
local refhead
refhead="$(git rev-parse --quiet --verify "$1")"
if [ -n "$refhead" ]
then
shift

View file

@ -45,11 +45,10 @@ if [ -n "$MERGES_ARG" ] && [ -n "$SUMMARY_BY_LINE" ]; then
exit 1
fi
commit="HEAD"
if [ -n "$SUMMARY_BY_LINE" ]; then
paths=( "$@" )
else
commit="HEAD"
[ $# -ne 0 ] && commit=$*
fi
project=${PWD##*/}
@ -57,18 +56,17 @@ project=${PWD##*/}
#
# get date for the given <commit>
#
date() {
commit_date() {
# the $1 can be empty
# shellcheck disable=SC2086
git log $MERGES_ARG --pretty='format: %ai' $1 | cut -d ' ' -f 2
git log $MERGES_ARG --pretty='format: %ai' "$1" | cut -d ' ' -f 2
}
#
# get active days for the given <commit>
#
active_days() {
# shellcheck disable=SC2086
date $1 | sort -r | uniq | awk '
commit_date "$1" | sort -r | uniq | awk '
{ sum += 1 }
END { print sum }
'
@ -79,7 +77,7 @@ active_days() {
#
commit_count() {
# shellcheck disable=SC2086
git log $MERGES_ARG --oneline $commit | wc -l | tr -d ' '
git log $MERGES_ARG --oneline "$commit" | wc -l | tr -d ' '
}
#
@ -216,19 +214,17 @@ print_summary_by_line() {
print_summary() {
if [ "$OUTPUT_STYLE" == "tabular" ]; then
tabular_headers="# Repo $SP Age $SP Last active $SP Active on $SP Commits $SP Uncommitted $SP Branch"
echo -e "$tabular_headers\n$project $SP $(repository_age) $SP $(last_active) $SP $(active_days $commit) days $SP $(commit_count $commit) $SP $(uncommitted_changes_count) $SP $(current_branch_name)" | column -t -s "$COLUMN_CMD_DELIMTER"
echo -e "$tabular_headers\n$project $SP $(repository_age) $SP $(last_active) $SP $(active_days "$commit") days $SP $(commit_count "$commit") $SP $(uncommitted_changes_count) $SP $(current_branch_name)" | column -t -s "$COLUMN_CMD_DELIMTER"
elif [ "$OUTPUT_STYLE" == "oneline" ]; then
echo "$project / age: $(repository_age) / last active: $(last_active) / active on $(active_days $commit) days / commits: $(commit_count $commit) / uncommitted: $(uncommitted_changes_count) / branch: $(current_branch_name)"
echo "$project / age: $(repository_age) / last active: $(last_active) / active on $(active_days "$commit") days / commits: $(commit_count "$commit") / uncommitted: $(uncommitted_changes_count) / branch: $(current_branch_name)"
else
echo
echo " project : $project"
echo " repo age : $(repository_age)"
echo " branch: : $(current_branch_name)"
echo " last active : $(last_active)"
# shellcheck disable=SC2086
echo " active on : $(active_days $commit) days"
# shellcheck disable=SC2086
echo " commits : $(commit_count $commit)"
echo " active on : $(active_days "$commit") days"
echo " commits : $(commit_count "$commit")"
# The file count doesn't support passing a git ref so ignore it if a ref is given
if [ "$commit" == "HEAD" ]; then
@ -239,10 +235,10 @@ print_summary() {
if [ -n "$DEDUP_BY_EMAIL" ]; then
# the $commit can be empty
# shellcheck disable=SC2086
git shortlog $MERGES_ARG -n -s -e $commit | dedup_by_email | format_authors
git shortlog $MERGES_ARG -n -s -e "$commit" | dedup_by_email | format_authors
else
# shellcheck disable=SC2086
git shortlog $MERGES_ARG -n -s $commit | format_authors
git shortlog $MERGES_ARG -n -s "$commit" | format_authors
fi
fi
}