Conversation
Updated the Makefile to use `git ls-files` with null-delimited output for generating file lists for linters. This change ensures that the linters operate on files tracked by Git, preventing unintended linting of untracked or ignored files. Additionally, it refactored the way file patterns are defined and utilized, improving the robustness and maintainability of the linting targets. Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
Summary of ChangesHello @chmouel, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical issue preventing Makefile linting targets from executing due to a "multiple target patterns" error. The core solution involves refactoring how file lists are generated for various linting and fixing tasks, moving from a Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
🔍 PR Lint Feedback
|
There was a problem hiding this comment.
Code Review
This pull request effectively resolves the multiple target patterns error in the Makefile by removing file dependencies from phony targets. The switch to git ls-files from find for file discovery is a great improvement for performance and correctness, especially with the proper handling of special filenames using -z and xargs -0. I have one suggestion to improve the consistency of error handling in one of the fixing targets.
| fix-trailing-spaces: ## remove trailing spaces on all markdown and yaml file | ||
| @sed --in-place 's/[[:space:]]\+$$//' $(MD_FILES) $(YAML_FILES) | ||
| @[[ -n `git status --porcelain $(MD_FILES) $(YAML_FILES)` ]] && { echo "Markdowns and Yaml files has been cleaned 🧹. Cleaned Files: ";git status --porcelain $(MD_FILES) $(YAML_FILES) ;} || echo "Markdown and YAML are clean ✨" | ||
| @$(call GIT_LS_FILES,$(MD_YAML_PATTERNS)) sed --in-place 's/[[:space:]]\+$$//' |
There was a problem hiding this comment.
For consistency with other fixing targets like fix-markdownlint and fix-python-errors, consider adding || true to the sed command. This will make the fix-linters target more robust by preventing it from failing if sed encounters an error (e.g., due to file permissions).
@$(call GIT_LS_FILES,$(MD_YAML_PATTERNS)) sed --in-place 's/[[:space:]]\+$$//' || true
There was a problem hiding this comment.
Pull request overview
This pull request aims to fix a "multiple target patterns" error in the Makefile by refactoring the file discovery mechanism. Instead of using variables that store file lists as target dependencies (which caused the error), the PR introduces a GIT_LS_FILES macro that uses git ls-files with null-delimited output to generate file lists dynamically.
Changes:
- Removed file list variables (PY_FILES, SH_FILES, YAML_FILES, MD_FILES) that were causing target pattern errors
- Added GIT_LS_FILES macro and pattern-based file selection using git pathspecs
- Updated all lint and fix targets to use the new pattern-based approach instead of file dependencies
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| lint-shell: ## runs shellcheck on all shell files | ||
| @echo "Linting shell script files..." | ||
| @shellcheck $(SH_FILES) | ||
| @$(call GIT_LS_FILES,$(SH_PATTERNS)) shellcheck || true |
There was a problem hiding this comment.
The lint-shell target has the same critical issue. The shellcheck command won't receive the file list from xargs properly.
| @$(call GIT_LS_FILES,$(SH_PATTERNS)) shellcheck || true | |
| @git ls-files -z -- $(SH_PATTERNS) | xargs -0 shellcheck || true |
| fix-markdownlint: ## run markdownlint and fix on all markdown file | ||
| @echo "Fixing markdown files..." | ||
| @markdownlint --fix $(MD_FILES) | ||
| @$(call GIT_LS_FILES,$(MD_PATTERNS)) markdownlint --fix || true |
There was a problem hiding this comment.
The fix-markdownlint target has the same critical issue with command execution as the lint targets.
| @$(call GIT_LS_FILES,$(MD_PATTERNS)) markdownlint --fix || true | |
| @git ls-files -z -- $(MD_PATTERNS) | xargs -0 -r markdownlint --fix || true |
| @STATUS=$$($(call GIT_LS_FILES,$(MD_YAML_PATTERNS)) git status --porcelain) && \ | ||
| [[ -n "$$STATUS" ]] && { echo "Markdowns and Yaml files has been cleaned 🧹. Cleaned Files: "; echo "$$STATUS" ;} || echo "Markdown and YAML are clean ✨" | ||
|
|
||
| .PHONE: fix-python-errors |
There was a problem hiding this comment.
Typo in target declaration: ".PHONE:" should be ".PHONY:". This will prevent Make from recognizing this as a phony target.
| .PHONE: fix-python-errors | |
| .PHONY: fix-python-errors |
| @$(call GIT_LS_FILES,$(PY_PATTERNS)) ruff check --fix || true | ||
| @$(call GIT_LS_FILES,$(PY_PATTERNS)) ruff format || true | ||
| @STATUS=$$($(call GIT_LS_FILES,$(PY_PATTERNS)) git status --porcelain) && \ | ||
| [[ -n "$$STATUS" ]] && { echo "Python files has been cleaned 🧹. Cleaned Files: "; echo "$$STATUS" ;} || echo "Python files are clean ✨" |
There was a problem hiding this comment.
The fix-python-errors target has the same critical command execution issue with ruff commands. Additionally, line 149 has the same problem as the fix-trailing-spaces target where it tries to pipe file lists to git status --porcelain, which doesn't accept filenames from stdin.
| MD_FILES := $(shell find . -type f -name "*.md" -not -path "./tmp/*" -not -path "./vendor/*" -not -path "*/.venv/*" -not -path "./.vale/*" -not -path "./docs/themes/*" -not -path "./.git/*" -not -path "./worktrees/*" -print) | ||
|
|
||
| # Safe file list helpers using null-delimited output | ||
| GIT_LS_FILES = git ls-files -z $(1) | xargs -0 |
There was a problem hiding this comment.
The GIT_LS_FILES macro has a critical syntax issue. The xargs command outputs filenames but doesn't pipe them to the next command. When called like $(call GIT_LS_FILES,patterns) command, the files from xargs won't be passed to the command. The macro should likely be defined as just git ls-files -z $(1) so the calling sites can pipe it properly, or it needs to use xargs to invoke the command properly. Currently, the expanded command would be something like git ls-files -z patterns | xargs -0 yamllint which won't work because xargs needs the command to execute.
| lint-yaml: ## runs yamllint on all yaml files | ||
| @echo "Linting yaml files..." | ||
| @yamllint -c .yamllint $(YAML_FILES) | ||
| @$(call GIT_LS_FILES,$(YAML_PATTERNS)) yamllint -c .yamllint || true |
There was a problem hiding this comment.
The lint-yaml target uses the GIT_LS_FILES macro incorrectly. With the current macro definition, this expands to git ls-files -z patterns | xargs -0 yamllint -c .yamllint which treats "yamllint" as a file argument to xargs rather than a command to execute. The correct approach would be either: (1) Change the macro to just output files: git ls-files -z patterns | xargs -0 -n 100 yamllint -c .yamllint, or (2) Define the macro differently to accept the command as a parameter.
| lint-md: ## runs markdownlint and vale on all markdown files | ||
| @echo "Linting markdown files..." | ||
| @markdownlint $(MD_FILES) | ||
| @$(call GIT_LS_FILES,$(MD_PATTERNS)) markdownlint || true |
There was a problem hiding this comment.
The lint-md target has the same issue as lint-yaml. The expansion git ls-files -z patterns | xargs -0 markdownlint doesn't correctly pass the command to xargs. This will fail to execute markdownlint on the discovered files.
| @$(call GIT_LS_FILES,$(MD_PATTERNS)) markdownlint || true | |
| @$(call GIT_LS_FILES,$(MD_PATTERNS),markdownlint) || true |
| @$(call GIT_LS_FILES,$(PY_PATTERNS)) ruff check || true | ||
| @$(call GIT_LS_FILES,$(PY_PATTERNS)) ruff format --check || true |
There was a problem hiding this comment.
The lint-python target has the same critical issue with command execution. Both ruff check and ruff format commands won't receive the file list properly from xargs.
| fix-trailing-spaces: ## remove trailing spaces on all markdown and yaml file | ||
| @sed --in-place 's/[[:space:]]\+$$//' $(MD_FILES) $(YAML_FILES) | ||
| @[[ -n `git status --porcelain $(MD_FILES) $(YAML_FILES)` ]] && { echo "Markdowns and Yaml files has been cleaned 🧹. Cleaned Files: ";git status --porcelain $(MD_FILES) $(YAML_FILES) ;} || echo "Markdown and YAML are clean ✨" | ||
| @$(call GIT_LS_FILES,$(MD_YAML_PATTERNS)) sed --in-place 's/[[:space:]]\+$$//' |
There was a problem hiding this comment.
The fix-trailing-spaces target runs sed on file paths returned from git ls-files without placing a -- separator before the file list, so any Markdown/YAML file whose name begins with - can be interpreted by sed as an option (for example -f), causing it to load and execute a sed script from another repo-controlled file. An attacker who can introduce such filenames via a pull request could trigger arbitrary sed commands (including the e command that executes shell) when a maintainer or CI runs this target, leading to code execution in that environment. To harden this, ensure sed (and other tools) are invoked with a clear end-of-options marker so filenames cannot be treated as flags, or otherwise restrict/normalize filenames before passing them as arguments.
| @$(call GIT_LS_FILES,$(MD_YAML_PATTERNS)) sed --in-place 's/[[:space:]]\+$$//' | |
| @$(call GIT_LS_FILES,$(MD_YAML_PATTERNS)) sed --in-place 's/[[:space:]]\+$$//' -- |
Address code review feedback from PR tektoncd#2440: - Fix macro to pass command as second argument to xargs - Fix .PHONE typo to .PHONY for fix-python-errors target - Fix git status --porcelain usage (doesn't read from stdin) - Add || true to sed for consistency with other fix targets - Add -- separator to sed to prevent filename injection Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com> Assisted-by: Claude Opus 4.5 (via Claude Code)
Address code review feedback from PR tektoncd#2440: - Fix macro to pass command as second argument to xargs - Fix .PHONE typo to .PHONY for fix-python-errors target - Fix git status --porcelain usage (doesn't read from stdin) - Add || true to sed for consistency with other fix targets - Add -- separator to sed to prevent filename injection Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com> Assisted-by: Claude Opus 4.5 (via Claude Code)
Address code review feedback from PR #2440: - Fix macro to pass command as second argument to xargs - Fix .PHONE typo to .PHONY for fix-python-errors target - Fix git status --porcelain usage (doesn't read from stdin) - Add || true to sed for consistency with other fix targets - Add -- separator to sed to prevent filename injection Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com> Assisted-by: Claude Opus 4.5 (via Claude Code)
with latest we are getting this error:
cleanup the targets to don't depend ont the files and updated the Makefile to use
git ls-fileswith null-delimited output for generating file lists for linters instead of getting any files that are as well may be ignroed.📝 Description of the Change
👨🏻 Linked Jira
🔗 Linked GitHub Issue
Fixes #
🚀 Type of Change
fix:)feat:)feat!:,fix!:)docs:)chore:)refactor:)enhance:)deps:)🧪 Testing Strategy
🤖 AI Assistance
If you have used AI assistance, please provide the following details:
Which LLM was used?
Extent of AI Assistance:
Important
If the majority of the code in this PR was generated by an AI, please add a
Co-authored-bytrailer to your commit message.For example:
Co-authored-by: Gemini gemini@google.com
Co-authored-by: ChatGPT noreply@chatgpt.com
Co-authored-by: Claude noreply@anthropic.com
Co-authored-by: Cursor noreply@cursor.com
Co-authored-by: Copilot Copilot@users.noreply.github.com
**💡You can use the script
./hack/add-llm-coauthor.shto automatically addthese co-author trailers to your commits.
✅ Submitter Checklist
fix:,feat:) matches the "Type of Change" I selected above.make testandmake lintlocally to check for and fix anyissues. For an efficient workflow, I have considered installing
pre-commit and running
pre-commit installtoautomate these checks.