Skip to content

feat: add use_gitignore option to exclude ignored files from sources/generates#2773

Merged
vmaerten merged 11 commits into
mainfrom
git-ignore
Jun 29, 2026
Merged

feat: add use_gitignore option to exclude ignored files from sources/generates#2773
vmaerten merged 11 commits into
mainfrom
git-ignore

Conversation

@vmaerten

@vmaerten vmaerten commented Apr 4, 2026

Copy link
Copy Markdown
Member

Summary

Add use_gitignore: true option at the Taskfile (global) and task level to automatically exclude files matching .gitignore rules from sources and generates glob resolution

Uses lightweight sabhiram/go-gitignore library (zero transitive dependencies) instead of go-git

@vmaerten vmaerten changed the title ✨ feat: add gitignore option to exclude ignored files from sources/generates feat: add gitignore option to exclude ignored files from sources/generates Apr 4, 2026
@vmaerten vmaerten changed the title feat: add gitignore option to exclude ignored files from sources/generates feat: add use_gitignore option to exclude ignored files from sources/generates Apr 4, 2026
@vmaerten vmaerten marked this pull request as ready for review April 9, 2026 06:09
@trulede

trulede commented Apr 19, 2026

Copy link
Copy Markdown
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 .gitignore file, or similar.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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_gitignore and 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-gitignore dependency.

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.

Comment thread internal/fingerprint/gitignore.go Outdated
Comment thread internal/fingerprint/gitignore.go Outdated
Comment thread internal/fingerprint/gitignore.go Outdated
Comment thread taskfile/ast/task.go Outdated
Comment thread go.mod Outdated
vmaerten added 7 commits June 7, 2026 15:02
…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.
vmaerten and others added 4 commits June 7, 2026 16:16
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 vmaerten merged commit 616433d into main Jun 29, 2026
18 checks passed
@vmaerten vmaerten deleted the git-ignore branch June 29, 2026 13:39
vmaerten added a commit that referenced this pull request Jun 29, 2026
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.

3 participants