-
-
Notifications
You must be signed in to change notification settings - Fork 9
fix: HasChangesOtherThan now ignores gitignored files #34
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
fix: HasChangesOtherThan now ignores gitignored files #34
Conversation
go-git reports gitignored files as Untracked, unlike native git. This caused HasChangesOtherThan() to incorrectly detect changes when only gitignored files existed (e.g., progress-*.txt files). The fix checks IsIgnored() for untracked files before counting them as changes, matching the behavior of IsDirty(). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
Pull request overview
This PR fixes a bug where HasChangesOtherThan() incorrectly detected changes when only gitignored files existed in the worktree. The issue occurred because go-git reports gitignored files as Untracked, unlike native git's git status which filters them out.
Changes:
- Added gitignore filtering for untracked files in
HasChangesOtherThan()method - Updated documentation to clarify that gitignored files are excluded
- Added comprehensive test coverage for gitignored file scenarios
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/git/git.go | Added check to skip untracked files that are gitignored using the existing IsIgnored() helper, matching behavior of IsDirty() |
| pkg/git/git_test.go | Added two test cases: one verifying gitignored files don't count as changes, another verifying mixed scenarios work correctly |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
overall the fix is correct - addresses real issue where go-git reports gitignored files as linter issue
suggest checking gitignore before for path, s := range status {
if path == relPath {
continue
}
// skip gitignored untracked files
if s.Worktree == git.Untracked && s.Staging == git.Unmodified {
ignored, err := r.IsIgnored(path)
if err != nil {
return false, fmt.Errorf("check ignored: %w", err)
}
if ignored {
continue
}
}
if r.fileHasChanges(s) {
return true, nil
}
}this way: first filter out files we don't care about, then check for changes. |
Refactor to use early continue instead of nested if blocks to satisfy nestif linter check. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
umputun
left a comment
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.
LGTM
|
@umputun thanks! fastest bugfix ever and thanks for this amazing tool |
Summary
HasChangesOtherThan()incorrectly detected changes when only gitignored files existedUntracked, unlike native git'sgit statusIsIgnored()on untracked files before counting them as changesRoot Cause
The
fileHasChanges()helper treatsUntrackedfiles as changes without checking if they're gitignored. This caused false positives when gitignored files (likeprogress-*.txt) existed in the worktree.The fix uses the existing
IsIgnored()helper to skip gitignored untracked files, matching the behavior already implemented inIsDirty().Test plan
returns_false_when_only_gitignored_file_existsreturns_true_when_gitignored_and_non-gitignored_files_exist🤖 Generated with Claude Code