From 8eca06b788ffc6e71e179dc76d0b0ef8717808da Mon Sep 17 00:00:00 2001 From: Vladimir Vagaytsev Date: Mon, 4 Dec 2023 15:55:58 +0100 Subject: [PATCH] refactor: simplify re-init of exclude filter --- core/src/vcs/git-repo.ts | 9 +++------ core/src/vcs/git.ts | 8 +++----- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/core/src/vcs/git-repo.ts b/core/src/vcs/git-repo.ts index 8a5b760c3c..8f5dd878d2 100644 --- a/core/src/vcs/git-repo.ts +++ b/core/src/vcs/git-repo.ts @@ -31,17 +31,14 @@ const getIncludeExcludeFiles: IncludeExcludeFilesHandler { const { include, path, scanFromProjectRoot } = params - let { exclude } = params - - if (!exclude) { - exclude = [] - } // Make sure action config is not mutated. + let exclude = !params.exclude ? [] : [...params.exclude] + // Do the same normalization of the excluded paths like in GitHandler. // This might be redundant because the non-normalized paths will be handled by augmentGlobs below. // But this brings no harm and makes the implementation more clear. - exclude = [...exclude.map(normalize)] + exclude = exclude.map(normalize) // We allow just passing a path like `foo` as include and exclude params // Those need to be converted to globs, but we don't want to touch existing globs diff --git a/core/src/vcs/git.ts b/core/src/vcs/git.ts index 996345e3ea..3de4316832 100644 --- a/core/src/vcs/git.ts +++ b/core/src/vcs/git.ts @@ -81,13 +81,11 @@ interface GitSubTreeIncludeExcludeFiles extends BaseIncludeExcludeFiles { const getIncludeExcludeFiles: IncludeExcludeFilesHandler = async ( params: GetFilesParams ) => { - let { include, exclude } = params - - if (!exclude) { - exclude = [] - } + let include = params.include // Make sure action config is not mutated. + let exclude = !params.exclude ? [] : [...params.exclude] + // It looks like paths with redundant '.' and '..' parts // do not work well along with --exclude and --glob-pathspecs flags. exclude = [...exclude.map(normalize), "**/.garden/**/*"]