mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 07:26:17 -04:00
Fix all ShellCheck errors and add to CI (#1179)
This commit is contained in:
parent
fdaca2cd26
commit
e691826b4b
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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#* }
|
||||
|
|
@ -103,7 +105,7 @@ do
|
|||
do
|
||||
printf "-"
|
||||
done
|
||||
printf "(%s)" $num
|
||||
printf "(%s)" "$num"
|
||||
else
|
||||
for (( i = 0; i > num; i-- ))
|
||||
do
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
13
bin/git-scp
13
bin/git-scp
|
|
@ -59,7 +59,7 @@ function php_lint()
|
|||
|
||||
function _dos2unix()
|
||||
{
|
||||
command -v dos2unix > /dev/null && dos2unix $@
|
||||
command -v dos2unix > /dev/null && dos2unix "$@"
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
@ -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 $?
|
||||
|
|
@ -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"))" &&
|
||||
|
|
@ -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"
|
||||
}
|
||||
|
|
@ -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…
Reference in a new issue