Skip to content

Commit

Permalink
format.sh: Avoid exit when no files changed
Browse files Browse the repository at this point in the history
This script is set to exit any time a command fails. In the case of
this line, the script unexpectedly errors out on this check to see if
any files have changed that are relevant for the `clang-format` tool.
The `grep` specifically will return non-zero in this case.

The workaround here is to catch the error and run `echo -e` instead,
which we know will succeed and the end result is what we want (the
list of changed files will be empty).

This allows the script to continue to completion, even when
`clang-format` has nothing to do.

Signed-off-by: Russell Bryant <[email protected]>
  • Loading branch information
russellb committed Aug 27, 2024
1 parent fc050dd commit 0956a41
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ clang_format_changed() {
MERGEBASE="$(git merge-base origin/main HEAD)"

# Get the list of changed files, excluding the specified ones
changed_files=$(git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.h' '*.cpp' '*.cu' '*.cuh' | grep -vFf <(printf "%s\n" "${CLANG_FORMAT_EXCLUDES[@]}"))
changed_files=$(git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.h' '*.cpp' '*.cu' '*.cuh' | (grep -vFf <(printf "%s\n" "${CLANG_FORMAT_EXCLUDES[@]}") || echo -e))
if [ -n "$changed_files" ]; then
echo "$changed_files" | xargs -P 5 clang-format -i
fi
Expand Down

0 comments on commit 0956a41

Please sign in to comment.