-
Notifications
You must be signed in to change notification settings - Fork 0
Add Automatic Gitignore Support #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e600e4e
012ed5b
141cff7
313024d
aa5dfd3
1c245d5
710ab29
26d6448
8c775f6
20d723c
c5d7f90
1ce2b17
31e8237
85568be
8387c3b
cbfe284
25c5ee6
29b79e2
a327031
342b704
3fb23c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,274 @@ | ||||||
| # Packs first mode | ||||||
| # Advanced Usage | ||||||
|
|
||||||
| This document covers advanced configuration options and features in `pks`. | ||||||
|
|
||||||
| ## Packs First Mode | ||||||
|
|
||||||
| Packs first mode can be used if your entire team is using `packs`. Currently, the only thing this does is change the copy in `package_todo.yml` files to reference `pks` instead of `packwerk`. | ||||||
|
|
||||||
| There are two ways to enable this: | ||||||
| 1. Rename `packwerk.yml` to `packs.yml` and packs first mode will be automatically enabled. | ||||||
| 2. Set `packs_first_mode: true` in your `packwerk.yml` | ||||||
|
|
||||||
| --- | ||||||
|
|
||||||
| ## Gitignore Support | ||||||
|
|
||||||
| ### Overview | ||||||
|
|
||||||
| By default, `pks` automatically respects `.gitignore` files when analyzing your codebase. This means any files or directories listed in your `.gitignore` will be excluded from pack analysis. | ||||||
|
|
||||||
| This feature: | ||||||
| - ✅ Reduces noise by excluding generated files, temporary files, and vendor code | ||||||
| - ✅ Improves performance by skipping ignored directories during traversal | ||||||
| - ✅ Works automatically without any configuration | ||||||
| - ✅ Can be disabled if you need behavior identical to `packwerk` | ||||||
|
|
||||||
| ### What Files Are Respected? | ||||||
|
|
||||||
| `pks` checks multiple gitignore sources in this order: | ||||||
|
|
||||||
| 1. **Local `.gitignore`** - The `.gitignore` file in your repository root | ||||||
| 2. **Global gitignore** - Your user-level gitignore file from `git config --global core.excludesFile` | ||||||
| 3. **Git exclude file** - The `.git/info/exclude` file in your repository | ||||||
|
|
||||||
| All standard gitignore features are supported: | ||||||
| - Pattern matching (e.g., `*.log`, `tmp/`) | ||||||
| - Directory exclusion (e.g., `node_modules/`) | ||||||
| - Negation patterns (e.g., `!important.log`) | ||||||
| - Comments (lines starting with `#`) | ||||||
|
|
||||||
| ### Configuration | ||||||
|
|
||||||
| #### Disabling Gitignore Support | ||||||
|
|
||||||
| If you need to disable automatic gitignore support, add this to your `packwerk.yml` or `packs.yml`: | ||||||
|
|
||||||
| ```yaml | ||||||
| # Disable automatic gitignore support | ||||||
| respect_gitignore: false | ||||||
| ``` | ||||||
| #### When to Disable? | ||||||
| You might want to disable gitignore support if: | ||||||
| - You have files in `.gitignore` that should still be analyzed by `pks` | ||||||
| - You're migrating from `packwerk` and want identical behavior | ||||||
| - You have custom `exclude:` patterns that you prefer to manage manually | ||||||
| - You need to analyze generated code that's normally gitignored | ||||||
|
|
||||||
| #### Default Behavior | ||||||
|
|
||||||
| If not specified, `respect_gitignore` defaults to `true` (enabled). | ||||||
|
|
||||||
| ### Precedence of Ignore Rules | ||||||
|
|
||||||
| When determining whether to process a file, `pks` applies rules in this order (highest priority first): | ||||||
|
|
||||||
| 1. **Include patterns** - Files matching `include:` patterns in configuration | ||||||
| 2. **Gitignore patterns** - Files/directories in `.gitignore` (if `respect_gitignore: true`) | ||||||
| 3. **Exclude patterns** - Files matching `exclude:` patterns in configuration | ||||||
| 4. **Default exclusions** - Hardcoded exclusions (e.g., `{bin,node_modules,script,tmp,vendor}/**/*`) | ||||||
|
|
||||||
| This precedence allows you to: | ||||||
| - Override gitignore by explicitly including files via `include:` patterns | ||||||
| - Add additional exclusions beyond what's in `.gitignore` via `exclude:` patterns | ||||||
| - Layer multiple levels of filtering for fine-grained control | ||||||
|
|
||||||
| ### Example Configuration | ||||||
|
|
||||||
| ```yaml | ||||||
| # packwerk.yml | ||||||
| # Enable gitignore support (this is the default) | ||||||
| respect_gitignore: true | ||||||
| # Include patterns (highest priority - override gitignore) | ||||||
|
||||||
| # Include patterns (highest priority - override gitignore) | |
| # Include patterns (what file extensions to analyze) |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This troubleshooting advice incorrectly states that include patterns can override gitignore patterns. As noted in a previous comment on lines 64-76, the implementation actually checks gitignore first (with a continue statement), so gitignored files are skipped before include patterns are evaluated.
This suggestion should be removed or corrected to indicate that negation patterns in .gitignore (step 4) are the proper way to un-ignore specific files, not include patterns in packwerk.yml.
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This statement is incorrect. Based on the implementation, include patterns do NOT override gitignore patterns. The gitignore check happens before include pattern matching, so gitignored files will never reach the include pattern check.
The comment at line 189 "This will include ALL .rb files, even if gitignored" is misleading - gitignored .rb files will still be skipped regardless of this include pattern.
This section should be corrected to accurately reflect the actual behavior.
| - "**/*.rb" # This will include ALL .rb files, even if gitignored | |
| - "**/*.rb" # This will include all non-gitignored .rb files; gitignored files will still be excluded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation claims that "Include patterns" have highest priority and can override gitignore patterns (line 68-74), but this is incorrect based on the implementation.
In the code (
src/packs/walk_directory.rslines 305-310), gitignored files are skipped with acontinuestatement before the include patterns are checked (line 328). This means gitignored files cannot be overridden by include patterns.The actual precedence order is:
.gitignoreare skipped first (ifrespect_gitignore: true)include:patterns to be consideredexclude:are filtered outThe documentation should be corrected to reflect this actual behavior, or the implementation should be changed to allow include patterns to override gitignore (though the current behavior seems more reasonable for most use cases).