From adbf28f42d0c54f92f19ad593b58061ea89c35a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20H=C3=B6ger?= Date: Fri, 18 Nov 2022 13:41:42 +0100 Subject: [PATCH] Use git check-ignore instead of a (incomplete) list of ignored files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The list-based method breaks down in case of ignored folders: If .gitignore contains foo/, foo/bar.py is still checked. Signed-off-by: Christoph Höger --- lib/functions/buildFileList.sh | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/lib/functions/buildFileList.sh b/lib/functions/buildFileList.sh index b4ef39ea..a7dff909 100755 --- a/lib/functions/buildFileList.sh +++ b/lib/functions/buildFileList.sh @@ -228,26 +228,6 @@ function BuildFileList() { fi fi - ############################### - # Load the ignored files list # - ############################### - debug "Loading the files list that Git ignores..." - mapfile -t GIT_IGNORED_FILES < <(git -C "${GITHUB_WORKSPACE}" status --ignored --porcelain=v1 --short --untracked-files=normal | grep '!!' | awk -F ' ' '{print $2}' | sed -e 's#^#'"${GITHUB_WORKSPACE}"/'#' | sort) - debug "GIT_IGNORED_FILES contents: ${GIT_IGNORED_FILES[*]}" - - # Build an associative array to avoid looping throug the ignored files list - local i - declare -g -A GIT_IGNORED_FILES_INDEX - for i in "${!GIT_IGNORED_FILES[@]}"; do - eval GIT_IGNORED_FILES_INDEX["${GIT_IGNORED_FILES[$i]}"]="$i" - done - debug "--- GIT_IGNORED_FILES_INDEX contents ---" - debug "-----------------------" - for i in "${!GIT_IGNORED_FILES_INDEX[@]}"; do - debug "key: $i, value: ${GIT_IGNORED_FILES_INDEX[$i]}" - done - debug "---------------------------------------------" - ######################################### # Check if the Ansible directory exists # ######################################### @@ -316,7 +296,7 @@ function BuildFileList() { ################################################### # Filter files if FILTER_REGEX_EXCLUDE is not set # ################################################### - if [ "${GIT_IGNORED_FILES_INDEX[$FILE]}" ] && [ "${IGNORE_GITIGNORED_FILES}" == "true" ]; then + if git check-ignore "$FILE" && [ "${IGNORE_GITIGNORED_FILES}" == "true" ]; then debug "${FILE} is ignored by Git. Skipping ${FILE}" continue fi