Skip to content

Conversation

@geri4
Copy link
Contributor

@geri4 geri4 commented Jan 26, 2026

Summary

  • Fixed bug where HasChangesOtherThan() incorrectly detected changes when only gitignored files existed
  • go-git reports gitignored files as Untracked, unlike native git's git status
  • Added check for IsIgnored() on untracked files before counting them as changes

Root Cause

The fileHasChanges() helper treats Untracked files as changes without checking if they're gitignored. This caused false positives when gitignored files (like progress-*.txt) existed in the worktree.

The fix uses the existing IsIgnored() helper to skip gitignored untracked files, matching the behavior already implemented in IsDirty().

Test plan

  • Added test: returns_false_when_only_gitignored_file_exists
  • Added test: returns_true_when_gitignored_and_non-gitignored_files_exist
  • All existing tests pass

🤖 Generated with Claude Code

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>
@geri4 geri4 requested a review from umputun as a code owner January 26, 2026 22:44
Copilot AI review requested due to automatic review settings January 26, 2026 22:44
Copy link

Copilot AI left a 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.

@umputun
Copy link
Owner

umputun commented Jan 26, 2026

overall

the fix is correct - addresses real issue where go-git reports gitignored files as Untracked while native git filters them out. good test coverage with both "only gitignored" and "mixed" scenarios.

linter issue

nestif fails on the new nested block:

pkg/git/git.go:351:1: `if r.fileHasChanges(s)` has complex nested blocks (complexity: 5)

suggest checking gitignore before fileHasChanges() - cleaner logic and fixes linter:

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>
Copy link
Owner

@umputun umputun left a comment

Choose a reason for hiding this comment

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

LGTM

@umputun umputun merged commit b89ce1f into umputun:master Jan 26, 2026
@geri4
Copy link
Contributor Author

geri4 commented Jan 26, 2026

@umputun thanks! fastest bugfix ever and thanks for this amazing tool

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.

2 participants