Skip to content

Commit aa38b4a

Browse files
committed
Don't rely on sort -V on non-Linux
1 parent fecde87 commit aa38b4a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

apply-format

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,22 @@ fi
188188
# clang-format-diff.
189189
if [ "$whole_file" = false ]; then
190190
invalid="/dev/null/invalid/path"
191+
if [ "${OSTYPE:-}" = "linux-gnu" ]; then
192+
readonly sort_version=-V
193+
else
194+
# On macOS, sort doesn't have -V.
195+
readonly sort_version=-n
196+
fi
191197
declare paths_to_try=()
192198
# .deb packages directly from upstream.
193199
# We try these first as they are probably newer than the system ones.
194200
while read -r f; do
195201
paths_to_try+=("$f")
196-
done < <(compgen -G "/usr/share/clang/clang-format-*/clang-format-diff.py" | sort -V -r)
202+
done < <(compgen -G "/usr/share/clang/clang-format-*/clang-format-diff.py" | sort "$sort_version" -r)
197203
# LLVM official releases (just untarred in /usr/local).
198204
while read -r f; do
199205
paths_to_try+=("$f")
200-
done < <(compgen -G "/usr/local/clang+llvm*/share/clang/clang-format-diff.py" | sort -V -r)
206+
done < <(compgen -G "/usr/local/clang+llvm*/share/clang/clang-format-diff.py" | sort "$sort_version" -r)
201207
# Maybe it's in the $PATH already? This is true for Ubuntu and Debian.
202208
paths_to_try+=( \
203209
"$(which clang-format-diff 2> /dev/null || echo "$invalid")" \

0 commit comments

Comments
 (0)