Skip to content

Keep a green run green when git cannot list updated files - #8796

Open
trevor-vaughan wants to merge 1 commit into
oxsecurity:mainfrom
trevor-vaughan:fix/8649-git-lfs
Open

Keep a green run green when git cannot list updated files#8796
trevor-vaughan wants to merge 1 commit into
oxsecurity:mainfrom
trevor-vaughan:fix/8649-git-lfs

Conversation

@trevor-vaughan

Copy link
Copy Markdown
Contributor

🦾 Written with LLM assistance [claude-opus-5]
💪 Reviewed by a human before submission


Summary

A run where every linter passed could still exit with an error. list_updated_files() ran repo.index.diff(None) without a guard, and on a read-only workspace whose repository uses git-lfs the clean filter has nowhere to write its temporary files, so the diff exits 128 and UpdatedSourcesReporter.produce_report() propagated a GitCommandError.

Listing updated files is best effort — the helper already returned [] with a warning for the two other cases it cannot answer, so this adds GitCommandError to that set. The UPDATED_SOURCES_REPORTER: false workaround is no longer needed.

Changes

  • megalinter/utils.py: catch git.GitCommandError in list_updated_files() and return []. GitPython drains stderr before raising, so the warning carries the workspace path and the failed command instead — that is all the user gets to diagnose from
  • Warn once per workspace: Linter.update_files_lint_results calls the helper once per linted file in file mode, so subsequent failures for the same workspace log at debug level
  • megalinter/tests/test_megalinter/utils_test.py: tests for the nominal listing, the git-lfs failure, the warn-once behavior, and both non-repository cases. Git config is neutralized (GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM, author/committer) so the caller's own filters never influence the diff
  • docs/reporters/UpdatedSourcesReporter.md: new "Empty updated sources folder" section explaining the cause and the .git-writable fix
  • CHANGELOG.md entry under Core

Fixes #8649

`list_updated_files()` called `repo.index.diff(None)` unguarded. On a
read-only workspace backed by git-lfs, the clean filter has nowhere to
write its temp files and the diff exits 128, so
`UpdatedSourcesReporter.produce_report()` raised `GitCommandError` and
failed a run in which every linter had passed.

Listing updated files is best effort, and the helper already returned
`[]` with a warning for the two other cases it cannot answer. It now
catches `GitCommandError` too. GitPython drains stderr before raising,
so the warning names the workspace and the failed command — otherwise
the user has nothing to diagnose from.

- fix(core): warn once per workspace instead of once per linted file
  - In `file` lint mode the helper runs per file, and a workspace that
    fails once keeps failing for the rest of the run; repeats drop to
    debug level
- test(core): cover the four `list_updated_files` outcomes
  - Nominal listing, the git-lfs failure, the warn-once behavior, and
    the two pre-existing non-repository cases. Git config is neutralized
    so the caller's global filters never reach the diff
- docs(reporters): explain an empty updated sources folder
  - `UpdatedSourcesReporter.md` names the read-only + git-lfs cause and
    points at mounting `.git` writable

Fixes: oxsecurity#8649
Assisted-by: Claude Opus 5
Signed-off-by: Trevor Vaughan <peiriannydd@gmail.com>

@nvuillam nvuillam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good PR, thanks @trevor-vaughan 😊

@nvuillam
nvuillam enabled auto-merge (squash) August 26, 2026 07:09
@nvuillam
nvuillam disabled auto-merge August 26, 2026 07:09
@nvuillam

Copy link
Copy Markdown
Member

@trevor-vaughan plz can u merge conflicts so i can merge ? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: UpdatedSourcesReporter can fail a passing run on a read-only workspace with git-lfs

2 participants