Skip to content

Commit

Permalink
fix: Improve Bash hygiene (#1056)
Browse files Browse the repository at this point in the history
* fix: Improve Bash hygiene

* Update quoting to account for new bugs

* quotes

* fix: Remove extra shellcheck comment
  • Loading branch information
hyperupcall authored Aug 18, 2023
1 parent 8af4389 commit 47e9402
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 26 deletions.
6 changes: 3 additions & 3 deletions bin/git-authors
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions bin/git-changelog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bin/git-guilt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ do
do
printf "+"
done
printf "(%s)" $num
printf "(%s)" "$num"
else
for (( i = 0; i < num; i++ ))
do
Expand Down
2 changes: 1 addition & 1 deletion bin/git-rebase-patch
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand Down
3 changes: 2 additions & 1 deletion bin/git-scp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 11 additions & 15 deletions bin/git-summary
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,28 @@ 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##*/}

#
# 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 }
'
Expand All @@ -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 ' '
}

#
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 47e9402

Please sign in to comment.