Skip to content

Commit

Permalink
Fix all ShellCheck errors and add to CI (#1179)
Browse files Browse the repository at this point in the history
  • Loading branch information
oikarinen authored Dec 21, 2024
1 parent fdaca2c commit e691826
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
env:
# NOTE: use env to pass the output in order to avoid possible injection attacks
FILES: "${{ steps.files.outputs.added_modified }}"
- name: Shellcheck
run: shellcheck --severity=error bin/* ./*.sh
- name: Lint and format Python with Ruff
uses: astral-sh/ruff-action@v2

Expand Down
2 changes: 1 addition & 1 deletion bin/git-create-branch
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ then
REMOTE=origin
fi

test -z $BRANCH && echo "branch argument required." 1>&2 && exit 1
test -z "$BRANCH" && echo "branch argument required." 1>&2 && exit 1

if [[ -n $REMOTE ]]
then
Expand Down
2 changes: 1 addition & 1 deletion bin/git-fork
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ else
# clone forked repo into current dir
git clone "${remote_prefix}${user}/${project}.git" "$project"
# add reference to origin fork so can merge in upstream changes
cd "$project"
cd "$project" || exit
git remote add upstream "${remote_prefix}${owner}/${project}.git"
git fetch upstream
fi
8 changes: 5 additions & 3 deletions bin/git-guilt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ do
esac
done

cd "$(git-root)" # cd for git blame
cd "$(git-root)" || exit # cd for git blame
MERGED_LOG=$(git_extra_mktemp)
if [[ $EMAIL == '-e' ]]
then
Expand All @@ -44,9 +44,11 @@ for file in $(git diff --name-only "$@")
do
test -n "$DEBUG" && echo "git blame $file"
# $1 - since $2 - until
# shellcheck disable=SC2086
git blame $NOT_WHITESPACE --line-porcelain "$1" -- "$file" 2> /dev/null |
LC_ALL=C sed -n "$PATTERN" | sort | uniq -c | LC_ALL=C sed 's/^\(.\)/- \1/' >> "$MERGED_LOG"
# if $2 not given, use current commit as "until"
# shellcheck disable=SC2086
git blame $NOT_WHITESPACE --line-porcelain "${2-@}" -- "$file" 2> /dev/null |
LC_ALL=C sed -n "$PATTERN" | sort | uniq -c | LC_ALL=C sed 's/^\(.\)/+ \1/' >> "$MERGED_LOG"
done
Expand All @@ -71,7 +73,7 @@ END {
printf("%d %s\n", contributors[people], people)
}
}
}' $MERGED_LOG | sort -nr | # only gawk supports built-in sort function
}' "$MERGED_LOG" | sort -nr | # only gawk supports built-in sort function
while read -r line
do
people=${line#* }
Expand Down Expand Up @@ -103,7 +105,7 @@ do
do
printf "-"
done
printf "(%s)" $num
printf "(%s)" "$num"
else
for (( i = 0; i > num; i-- ))
do
Expand Down
8 changes: 4 additions & 4 deletions bin/git-obliterate
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ do
file="$file"' '"$i"
shift
done
test -n "$*" && range="$*"
test -n "$*" && range=("$@")

test -z "$file" && echo "file required." 1>&2 && exit 1
if [ -z "$range" ]
if [ -z "${range[*]}" ]
then
git filter-branch -f --index-filter "git rm -r --cached ""$file"" --ignore-unmatch" \
--prune-empty --tag-name-filter cat -- --all
else
# don't quote $range so that we can forward multiple rev-list arguments
# $range is an array so that we can forward multiple rev-list arguments
git filter-branch -f --index-filter "git rm -r --cached ""$file"" --ignore-unmatch" \
--prune-empty --tag-name-filter cat -- $range
--prune-empty --tag-name-filter cat -- "${range[@]}"
fi
2 changes: 2 additions & 0 deletions bin/git-repl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ while true; do
esac

if [[ $cmd == !* ]]; then
# shellcheck disable=SC2086
eval ${cmd:1}
elif [[ $cmd == git* ]]; then
# shellcheck disable=SC2086
eval $cmd
else
eval git "$cmd"
Expand Down
13 changes: 7 additions & 6 deletions bin/git-scp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function php_lint()

function _dos2unix()
{
command -v dos2unix > /dev/null && dos2unix $@
command -v dos2unix > /dev/null && dos2unix "$@"
return 0
}

Expand All @@ -68,8 +68,8 @@ function _sanitize()
git config --get-all extras.scp.sanitize | while read -r i
do
case $i in
php_lint) php_lint $@;; # git config --global --add extras.scp.sanitize php_lint
dos2unix) _dos2unix $@;; # git config --global --add extras.scp.sanitize dos2unix
php_lint) php_lint "$@";; # git config --global --add extras.scp.sanitize php_lint
dos2unix) _dos2unix "$@";; # git config --global --add extras.scp.sanitize dos2unix
esac
done
return $?
Expand Down Expand Up @@ -107,6 +107,7 @@ function scp_and_stage
if [ -n "$list" ]
then
local _TMP=${0///}
# shellcheck disable=SC2086
echo "$list" > "$_TMP" &&
_sanitize $list &&
_info "Pushing to $remote ($(git config "remote.$remote.url"))" &&
Expand All @@ -131,7 +132,7 @@ function reverse_scp()
shift

local _TMP=${0///}
echo $@ > "$_TMP" &&
echo "$@" > "$_TMP" &&
rsync -rlDv --files-from="$_TMP" "$(git config "remote.$remote.url")/" ./ &&
rm "$_TMP"
}
Expand Down Expand Up @@ -173,8 +174,8 @@ case $(basename "$0") in
git-scp)
case $1 in
''|-h|'?'|help|--help) shift; _test_git_scp; _usage "$@";;
*) scp_and_stage $@;;
*) scp_and_stage "$@";;
esac
;;
git-rscp) reverse_scp $@;;
git-rscp) reverse_scp "$@";;
esac

0 comments on commit e691826

Please sign in to comment.