Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add shellcheck ci check #1179

Merged
merged 4 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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[@]}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "${range[*]}"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what SC2086 doc indicated and looks correct based on the bash docs.

If the subscript is ‘@’ or ‘’, the word expands to all members of the array name. These subscripts differ only when the word appears within double quotes. If the word is double-quoted, ${name[]} expands to a single word with the value of each array member separated by the first character of the IFS variable, and ${name[@]} expands each element of name to a separate word.

And indeed that seems to be the case:

$ ranges=( "range 1" "range 2" "range 3" ); for range in "${ranges[*]}"; do echo "$range"; done
range 1 range 2 range 3
$ ranges=( "range 1" "range 2" "range 3" ); for range in "${ranges[@]}"; do echo "$range"; done
range 1
range 2
range 3

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it

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
Loading