Skip to content

Commit

Permalink
Have check-mode.sh handle errors better on macOS
Browse files Browse the repository at this point in the history
In bash 3.2, which is used on macOS, `[[` commands don't invoke
`set -e` behavior. This adds an explicit check.

This also improves some code that sliced an array instead of using
the variables its elements were already assigned to. One of them is
used twice, and indexing in the existing usage would make the
meaning less clear. So the variables would not be reasonable to
eliminate by slicing the array, without other refactoring.
  • Loading branch information
EliahKagan committed Nov 28, 2024
1 parent a9b3b48 commit 530948d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions etc/check-mode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ readonly record_pattern='^([0-7]+) ([[:xdigit:]]+) [[:digit:]]+'$'\t''(.+)$'

# Check regular files named with a `.sh` suffix.
while IFS= read -rd '' record; do
[[ $record =~ $record_pattern ]]
[[ $record =~ $record_pattern ]] || exit 2 # bash 3.2 `set -e` doesn't cover this.
mode="${BASH_REMATCH[1]}"
oid="${BASH_REMATCH[2]}"
path="${BASH_REMATCH[3]}"

case "$mode" in
100644 | 100755)
check_item "${BASH_REMATCH[@]:1:3}"
check_item "$mode" "$oid" "$path"
;;
esac
done < <(git ls-files -sz -- '*.sh')
Expand Down

0 comments on commit 530948d

Please sign in to comment.