From 8e735a51b886b2e9942f6e33cdbf4155d054543c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 13 Jan 2021 13:27:51 +0100 Subject: [PATCH] contrib: handle no files in "nm-code-format.sh" Calling `clang-format` with no files means to read stdin, it thus hangs: $ ./contrib/scripts/nm-code-format.sh .git Also, the following does not work: $ ./contrib/scripts/nm-code-format.sh src/platform/ hangs. Seems there is a bug in `git ls-files` to not list all files: podman run -ti alpine:latest \ sh -c ' apk add git && git clone https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git && cd NetworkManager && git checkout -B tmp cd754680a6a0e35b286d4157269053ccc3996a32 && echo ">>>>>>BAD1: $PWD" && git ls-files -- src/platform/ ":(exclude)shared/n-acd" echo ">>>>>>GOOD1: $PWD" && git ls-files -- src/platform/ ":(exclude)shared/c-list" echo ">>>>>>GOOD2: $PWD" && git ls-files -- src/platform ":(exclude)shared/n-acd" echo ">>>>>>GOOD3: $PWD" && git ls-files -- src/vpn/ ":(exclude)shared/n-acd" ' Fixes: 9bef4ece925c ('contrib: improve nm-code-format.sh script') --- contrib/scripts/nm-code-format.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/scripts/nm-code-format.sh b/contrib/scripts/nm-code-format.sh index 0b48ed9bbb..70eb5a7f3a 100755 --- a/contrib/scripts/nm-code-format.sh +++ b/contrib/scripts/nm-code-format.sh @@ -113,6 +113,10 @@ if [ $SHOW_FILENAMES = 1 ]; then exit 0 fi +if [ "${#FILES[@]}" = 0 ]; then + die "Error: no files to check" +fi + FLAGS_TEST=( --Werror -n --ferror-limit=1 ) if [ $TEST_ONLY = 1 ]; then