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 cd754680a6 &&
         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: 9bef4ece92 ('contrib: improve nm-code-format.sh script')
This commit is contained in:
Thomas Haller 2021-01-13 13:27:51 +01:00
parent cd754680a6
commit 8e735a51b8
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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