feat: add use_gitignore option to exclude ignored files from sources/generates#2773
Merged
Conversation
Contributor
|
sabhiram/go-gitignore is a single file, you might just copy it into the Task repo. Perhaps a test for negation (!) in a nested |
There was a problem hiding this comment.
Pull request overview
Adds support for a use_gitignore option (global Taskfile + per-task override) to exclude files matched by .gitignore from sources / generates glob expansion, integrating the behavior into fingerprinting and watch-mode.
Changes:
- Extend Taskfile/task AST + JSON schema with
use_gitignoreand resolve task-level vs global precedence during compilation. - Update fingerprint globbing + up-to-date checks (checksum/timestamp),
for: { from: sources|generates }, and watch source collection to honor gitignore filtering. - Add gitignore-focused testdata and unit/integration tests, plus add
sabhiram/go-gitignoredependency.
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| website/src/public/schema.json | Adds use_gitignore to task + global schema. |
| watch.go | Passes gitignore setting into source collection globbing. |
| variables.go | Resolves global vs task override and threads flag into for: resolution. |
| testdata/gitignore/source.txt | New fixture source file. |
| testdata/gitignore/Taskfile.yml | New Taskfile fixture exercising global + per-task override. |
| testdata/gitignore/.gitignore | New fixture .gitignore. |
| taskfile/ast/taskfile.go | Adds global UseGitignore field + YAML decoding. |
| taskfile/ast/task.go | Adds per-task UseGitignore field + helper accessor. |
| task_test.go | Adds integration test validating checksum behavior with gitignored sources. |
| internal/fingerprint/sources_timestamp.go | Uses gitignore-aware globbing for timestamp checking. |
| internal/fingerprint/sources_checksum.go | Uses gitignore-aware globbing for checksum checking. |
| internal/fingerprint/glob.go | Adds useGitignore param and filters matched paths. |
| internal/fingerprint/gitignore_test.go | New unit tests for gitignore filtering behavior. |
| internal/fingerprint/gitignore.go | New implementation to load/apply .gitignore rules. |
| go.mod | Adds sabhiram/go-gitignore and updates module versions. |
| go.sum | Updates sums for added dependency + other module churn. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…rates When `gitignore: true` is set at the Taskfile or task level, files matching .gitignore rules are automatically excluded from sources and generates glob resolution. This prevents rebuilds triggered by changes to files that are in .gitignore (build artifacts, generated files, etc.). Uses go-git to load .gitignore patterns including nested .gitignore files, .git/info/exclude, and global gitignore configuration.
…dency go-git pulled ~30 transitive dependencies and recursively walked the entire worktree on every Globs() call. Replace with sabhiram/go-gitignore (zero dependencies) and a simple walk from task dir up to rootDir to collect .gitignore files. Pass rootDir (Taskfile ROOT_DIR) through the checker chain to bound the search scope.
Walk up from task dir to find .git instead of threading rootDir through Globs, checkers, and itemsFromFor. Gitignore rules are discarded if no .git is found, matching ripgrep's require_git behavior. This keeps the Globs signature clean and makes the future .taskignore integration straightforward (loaded at setup like .taskrc, separate boundary).
Rename the Taskfile/task option from `gitignore` to `use_gitignore` to avoid ambiguity (could be read as "ignore git" vs "use .gitignore"). Consistent with Biome's `useIgnoreFile` naming convention.
The sabhiram/go-gitignore dependency is unmaintained (since 2021) and has known gitignore spec gaps (* traverses /, ? broken, weak ** handling). Vendor the pattern/matcher core of go-git (plumbing/format/gitignore, v5.19.1) into internal/gitignore instead. It is ~185 lines of pure-stdlib, spec-correct code (proper **, anchoring, dir-only and negation handling). The file-walking helpers (dir.go) are intentionally omitted as they pull in go-billy and other go-git internals; importing the upstream package directly would re-add that transitive weight, which is why go-git was dropped before. This gains gitignore spec compliance while removing a direct dependency rather than adding one. The vendored code keeps its Apache-2.0 license (internal/gitignore/LICENSE) with attribution headers; upstream test cases are ported to table-driven stdlib tests to avoid an extra test dependency.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…te config - build a single matcher with per-directory domains so cross-file negations and rule precedence resolve like git - honor ignored parent directories (no re-inclusion of files beneath them) - load nested .gitignore files reached by deep globs - cache parsed .gitignore lines (mtime-invalidated) and repo-root lookups - keep patterns parsed before a scanner error; fix the out-of-tree path guard - propagate use_gitignore from included Taskfiles at merge time and make the Taskfile-level flag a *bool so an explicit false is preserved - apply the global fallback consistently in the task-list compile path Add golden integration tests and matcher unit tests covering the above.
The Taskfile struct decodes via a custom UnmarshalYAML, so the tag on the outer field is never used; the local struct's tag is what maps the key. Aligns with the other untagged Taskfile fields.
…e helper
Replace the duplicated cleanup/seed/run boilerplate across the five gitignore
integration tests with a gitignoreSeq{...}.run(t) helper. Golden names are
unchanged.
vmaerten
added a commit
that referenced
this pull request
Jun 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
use_gitignore: trueoption at the Taskfile (global) and task level to automatically exclude files matching.gitignorerules fromsourcesandgeneratesglob resolutionUses lightweight
sabhiram/go-gitignorelibrary (zero transitive dependencies) instead ofgo-git