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

feat: add shellcheck ci check #1179

merged 4 commits into from
Dec 21, 2024

Conversation

oikarinen
Copy link
Contributor

This was mentioned in some older PR. Autofixes in the same commit, some which seem actual bugs.

@@ -19,5 +19,5 @@ then
else
# don't quote $range 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.

range may contain multiple options, let's add a shellcheck disable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not an expert here but converted range to array so that multiple values would be quoted correctly in (theoretical) case they'd contain IFS or glob characters. LMKWYT? Could also just shellcheck disable=SC2086. Thanks for quick feedback on these few items 😎

@spacewander
Copy link
Collaborator

Let's merge main branch to make CI pass.

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

@spacewander
Copy link
Collaborator

@oikarinen
Would you solve #1180 (comment)?

@hyperupcall
Copy link
Collaborator

Thanks for adding this! This finishes up the rest of the ShellCheck improvements that I originally made in #1075 and #1056

Copy link
Collaborator

@hyperupcall hyperupcall left a comment

Choose a reason for hiding this comment

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

I spotted a few issues with the new changes. Could you go back and test any of the non-trivial changes to make sure they work?

bin/git-guilt Outdated
@@ -44,10 +44,10 @@ for file in $(git diff --name-only "$@")
do
test -n "$DEBUG" && echo "git blame $file"
# $1 - since $2 - until
git blame $NOT_WHITESPACE --line-porcelain "$1" -- "$file" 2> /dev/null |
git blame "$NOT_WHITESPACE" --line-porcelain "$1" -- "$file" 2> /dev/null |
Copy link
Collaborator

Choose a reason for hiding this comment

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

These new changes will cause git blame to fail whenever -w (or --ignore-whitespace) is not supplied at the command line.

bin/git-scp Outdated
_info "Pushing to $remote ($(git config "remote.$remote.url"))" &&
rsync -rlDv --files-from="$_TMP" ./ "$(git config "remote.$remote.url")/" &&
git add --force $list &&
git add --force "$list" &&
Copy link
Collaborator

@hyperupcall hyperupcall Nov 27, 2024

Choose a reason for hiding this comment

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

These new changes will now cause git add to fail in all cases (except the case where a single file is in list). Before, it would only fail on files that contained whitespace.

bin/git-scp Outdated
@@ -108,10 +108,10 @@ function scp_and_stage
then
local _TMP=${0///}
echo "$list" > "$_TMP" &&
_sanitize $list &&
_sanitize "$list" &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as below.

@oikarinen
Copy link
Contributor Author

I spotted a few issues with the new changes. Could you go back and test any of the non-trivial changes to make sure they work?

Thanks, if the test suite doesn't cover the changes probably best approach is to just ignore and perhaps have an issue(s) in backlog to fix those to limit the size of the PR.

@hyperupcall
Copy link
Collaborator

Thanks, if the test suite doesn't cover the changes probably best approach is to just ignore and perhaps have an issue(s) in backlog to fix those to limit the size of the PR.

Sounds good to me!

bin/git-scp Outdated
@@ -107,6 +107,7 @@ function scp_and_stage
if [ -n "$list" ]
then
local _TMP=${0///}
# shellcheck disable=SC2086
Copy link
Collaborator

Choose a reason for hiding this comment

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

Bad indent and bad location?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, tabs vs spaces thing. Sorry I rebased the branch to main instead of merge from old habits :(

@hyperupcall
Copy link
Collaborator

Great, thanks!

@hyperupcall hyperupcall merged commit e691826 into tj:main Dec 21, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants