Skip to content

![high](https://www.gstatic.com/codereviewagent/high-priority.svg) #114

@tylerblakex-netizen

Description

@tylerblakex-netizen

high

The use of || true will mask any error from git ls-files. For example, if this script is run in a directory that is not a git repository, git ls-files will fail, but || true will cause the command to succeed with a 0 exit code. The script will then incorrectly report that no shell scripts were found and exit successfully, potentially hiding a problem in the CI pipeline.

To make this more robust, I suggest explicitly checking the exit code of git ls-files. git ls-files exits with 1 when no files are found, which is an expected condition we want to handle gracefully. Any other non-zero exit code should be treated as a genuine error, and the script should fail.

set +e
mapfile -t FILES < <(git ls-files '*.sh' ':!:gradlew' ':!:.git/*')
GIT_LS_FILES_EC=$?
set -e

# Exit if git ls-files had a real error (not exit code 1 for 'no files found')
if [[ $GIT_LS_FILES_EC -ne 0 && $GIT_LS_FILES_EC -ne 1 ]]; then
  exit $GIT_LS_FILES_EC
fi

Originally posted by @gemini-code-assist in #113 (comment)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions