Isaac - 2022-11-22

I am trying to set up a script that runs cppcheck only on the files changed in a git diff, but seem to be experiencing some nondeterminism. I have seen the pre-commit script, but edited it to use the --project flag since my project uses a compile_commands.json generated by CMake.
The command looks something like:

changed_files=$(git diff-index --cached "$against" | \
    grep -E '[MA]   .*\.(c|cpp|cc|cxx)$' | \
    cut -f 2 |sed 's/^\(.*\)$/--file-filter=\1/' | tr '\n' ' ')

s=0
if [ -n "$changed_files" ]; then
    ./cppcheck \
        --inline-suppr \
        --xml \
        --enable=warning \
        --enable=style \
        --enable=performance \
        --enable=portability \
        --enable=missingInclude \
        --std=c11 --std=c++11 \
        -i [ignore_path1] \
        -i [ignore_path2] \
        -i [ignore_path3] \
        $changed_files \
        --project="$COMPILE_COMMANDS" 2> err.xml

the cppcheck invokation expands to:

./tools/cppcheck-2.8/cppcheck \
    --inline-suppr --xml --enable=warning --enable=style --enable=performance --enable=portability --enable=missingInclude --std=c11 --std=c++11 \ 
    -i [ignore_path1] -i [ignore_path2] -i [ignore_path3] \ 
    --file-filter=[changed_file_path1]  --file_filter=[changed_file_path2] ... (more file-filters) ... \ 
    --project=[path_to_compile_commands.json]

The ignore paths, changed file paths, and path to project database are all paths relative to the current directory.

I was originally specifying the project before the file fitlers, and was getting cppcheck: error: could not find any files matching the filter. After seeing the advice here, I moved the --project flag to the end. It worked once but the next time I got cppcheck: error: could not find any files matching the filter. again.

Platform is x86_64, CentOS 7 Linux