summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-09-23 15:30:16 +0200
committerThomas Haller <thaller@redhat.com>2022-09-23 15:32:28 +0200
commit2f8bb7c86a3e9445c1d945bfe8f95ab755d8b55c (patch)
treeea63f2bbedb9f4946028bb26c5801a649dfb8e3c
parentdbd2df3d1395d6073d3bbab2b512b7777c7972d7 (diff)
downloadNetworkManager-2f8bb7c86a3e9445c1d945bfe8f95ab755d8b55c.tar.gz
contrib: handle non-existing files with `nm-code-format.sh -u`
"-u" calls `git diff -name-only $UPSTREAM` to get a list of files. However, if $UPSTREAM contains a file that doesn't exist in the current checkout, we get a non-existing file name and clang-format will fail. Avoid that, by filtering only files that exist. Also, pass "--no-renames" option to git-diff.
-rwxr-xr-xcontrib/scripts/nm-code-format.sh15
1 files changed, 14 insertions, 1 deletions
diff --git a/contrib/scripts/nm-code-format.sh b/contrib/scripts/nm-code-format.sh
index a778818c8d..16008666a7 100755
--- a/contrib/scripts/nm-code-format.sh
+++ b/contrib/scripts/nm-code-format.sh
@@ -66,8 +66,20 @@ usage() {
printf " -- Separate options from filenames/directories\n"
}
+ls_files_exist() {
+ local OLD_IFS="$IFS"
+ local f
+
+ IFS=$'\n'
+ for f in $(cat) ; do
+ test -f "$f" && printf '%s\n' "$f"
+ done
+ IFS="$OLD_IFS"
+}
+
ls_files_filter() {
local OLD_IFS="$IFS"
+ local f
IFS=$'\n'
for f in $(cat) ; do
@@ -89,7 +101,8 @@ g_ls_files() {
if [ -z "$CHECK_UPSTREAM" ]; then
git ls-files -- "$pattern"
else
- git diff --name-only "$CHECK_UPSTREAM" -- "$pattern"
+ git diff --no-renames --name-only "$CHECK_UPSTREAM" -- "$pattern" \
+ | ls_files_exist
fi | ls_files_filter "$@"
}