Skip to content

Fix LimitDiffsByPathspec to handle exclusion-only pathspecs#44

Open
manato-tajiri wants to merge 1 commit into
sinclairtarget:masterfrom
manato-tajiri:fix/exclusion-pathspecs
Open

Fix LimitDiffsByPathspec to handle exclusion-only pathspecs#44
manato-tajiri wants to merge 1 commit into
sinclairtarget:masterfrom
manato-tajiri:fix/exclusion-pathspecs

Conversation

@manato-tajiri
Copy link
Copy Markdown

Description

When using only exclusion pathspecs (e.g., git who table -f -n 0 ':!*.json'), the Files and Lines (+/-) columns show 0 values. This happens because the concurrent execution path post-filters diffs using LimitDiffsByPathspec(), which incorrectly initializes shouldInclude to false when no include pathspecs are present.

Root Cause

In internal/git/git.go, the LimitDiffsByPathspec function splits pathspecs into includes and excludes. When only :!*.json is provided:

  • includes = [] (empty)
  • excludes = ["*.json"]

The initialization shouldInclude := false means every file diff is rejected since the loop over the empty includes slice never executes.

Fix

Changed shouldInclude := false to shouldInclude := len(includes) == 0.

This ensures that when only exclusion pathspecs are provided, all files are included by default and only removed if they match an exclusion pattern. Mixed include/exclude cases continue to work as before.

Testing

  • Verified on rubengmurray/no-unawaited-dot-catch-throw: git who table -f -n 0 ':!*.json' now correctly shows 9 files, 568/120 lines instead of 0/0
  • Both concurrent (GOMAXPROCS=4) and non-concurrent (GOMAXPROCS=1) paths produce identical correct results
  • Multiple exclusion patterns work correctly
  • All unit tests pass:
    ok  github.com/sinclairtarget/git-who/internal/git    0.792s
    ok  github.com/sinclairtarget/git-who/internal/tally   1.377s
    ok  github.com/sinclairtarget/git-who/internal/format  0.660s
    

When only exclusion pathspecs are provided (e.g., ':!*.json'), the
shouldInclude flag was initialized to false, causing all file diffs
to be discarded. Fixed by initializing shouldInclude to
len(includes) == 0, so that when no include pathspecs exist, all
files are included by default and only removed if they match an
exclusion pattern.

Fixes issue where 'git who table -f -n 0 ":!*.json"' showed 0
Files and 0 Lines (+/-) data.
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.

1 participant