From 2f8bb7c86a3e9445c1d945bfe8f95ab755d8b55c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 23 Sep 2022 15:30:16 +0200 Subject: [PATCH] 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. --- contrib/scripts/nm-code-format.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/contrib/scripts/nm-code-format.sh b/contrib/scripts/nm-code-format.sh index a778818c8..16008666a 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 "$@" }