Skip to content

Commit 40ecc9a

Browse files
authored
Fix .gitignore exclusion list build to include folders starting with a dot (#6978)
* Fix .gitignore exclusion list build to include folders starting with a dot * Improve performance of listing .gitignored files and advise on additional exclusions * yarn audit fix * cspell * flake * uv dep * [MegaLinter] Apply linters fixes --------- Co-authored-by: nvuillam <[email protected]>
1 parent 01107cf commit 40ecc9a

File tree

6 files changed

+46
-13
lines changed

6 files changed

+46
-13
lines changed

.cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,7 @@
16471647
"whitespaces",
16481648
"windir",
16491649
"wipeverb",
1650+
"wireit",
16501651
"workdir",
16511652
"workerpool",
16521653
"wrappy",

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l
1111
- Core
1212
- Improve files browsing performances
1313
- Optimize parallel linter processing and improve grouping logic
14-
- Improve performance of listing .gitignored files by sending excluded directories to git ls-files
14+
- Improve performance of listing .gitignored files by sending excluded directories to git ls-files
15+
- If there are more than 500 .gitignored files, advise to add more excluded directories using variable ADDITIONAL_EXCLUDED_DIRECTORIES, to improve performances
1516

1617
- New linters
1718

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,18 @@ Examples:
11251125

11261126
Warning: Not applicable with linters using CLI lint mode `project` ([see details](https://github.com/oxsecurity/megalinter/tree/main/docs/config-cli-lint-mode.md)).
11271127

1128+
You can also use variable **ADDITIONAL_EXCLUDED_DIRECTORIES** to add more excluded directories
1129+
1130+
Example:
1131+
1132+
```yaml
1133+
ADDITIONAL_EXCLUDED_DIRECTORIES:
1134+
- .wireit
1135+
- dist
1136+
- build
1137+
- vendor
1138+
```
1139+
11281140
<!-- config-filtering-section-end -->
11291141
<!-- config-apply-fixes-section-start -->
11301142
<!-- markdown-headers

mega-linter-runner/yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3365,9 +3365,9 @@ supports-color@^8.1.1:
33653365
has-flag "^4.0.0"
33663366

33673367
tar@^7.4.3, tar@^7.5.2:
3368-
version "7.5.2"
3369-
resolved "https://registry.yarnpkg.com/tar/-/tar-7.5.2.tgz#115c061495ec51ff3c6745ff8f6d0871c5b1dedc"
3370-
integrity sha512-7NyxrTE4Anh8km8iEy7o0QYPs+0JKBTj5ZaqHg6B39erLg0qYXN3BijtShwbsNSvQ+LN75+KV+C4QR/f6Gwnpg==
3368+
version "7.5.3"
3369+
resolved "https://registry.yarnpkg.com/tar/-/tar-7.5.3.tgz#e1a41236e32446f75e63b720222112c4ffe5b3a1"
3370+
integrity sha512-ENg5JUHUm2rDD7IvKNFGzyElLXNjachNLp6RaGf4+JOgxXHkqA+gq81ZAMCUmtMtqBsoU62lcp6S27g1LCYGGQ==
33713371
dependencies:
33723372
"@isaacs/fs-minipass" "^4.0.0"
33733373
chownr "^3.0.0"

megalinter/MegaLinter.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -869,11 +869,17 @@ def list_git_ignored_files(self):
869869
dirpath = os.path.realpath(self.github_workspace)
870870
repo = git.Repo(dirpath)
871871
excluded_dirs = utils.get_excluded_directories(self.request_id)
872-
normalized_excluded_dirs = set(
873-
os.path.normpath(excluded_dir).replace("\\", "/").lstrip("./")
874-
for excluded_dir in excluded_dirs
875-
)
876-
pathspec_excludes = [f":(exclude){excluded_dir}/**" for excluded_dir in normalized_excluded_dirs if excluded_dir]
872+
normalized_excluded_dirs = set()
873+
for excluded_dir in excluded_dirs:
874+
normalized = os.path.normpath(excluded_dir).replace("\\", "/")
875+
if normalized.startswith("./"):
876+
normalized = normalized[2:]
877+
normalized_excluded_dirs.add(normalized)
878+
pathspec_excludes = [
879+
f":(exclude){excluded_dir}/**"
880+
for excluded_dir in normalized_excluded_dirs
881+
if excluded_dir
882+
]
877883
ignored_files = repo.git.execute(
878884
[
879885
"git",
@@ -887,6 +893,15 @@ def list_git_ignored_files(self):
887893
).splitlines()
888894
ignored_files = map(lambda x: x + "**" if x.endswith("/") else x, ignored_files)
889895
ignored_files = sorted(list(ignored_files))
896+
# If there are more than 500 ignored files, advise to add more excluded
897+
# directories using variable ADDITIONAL_EXCLUDED_DIRECTORIES, to improve performances
898+
if len(ignored_files) > 300:
899+
logging.warning(
900+
f"⚠️ More than 300 .gitignored files have been detected ({len(ignored_files)}). "
901+
"To improve MegaLinter performances, consider adding more excluded directories "
902+
"using the ADDITIONAL_EXCLUDED_DIRECTORIES variable. "
903+
f"See {ML_DOC_URL}/config-filtering/"
904+
)
890905
return ignored_files
891906

892907
def initialize_output(self):

uv.lock

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)