Skip to content

Conversation

@twaugh
Copy link
Owner

@twaugh twaugh commented Oct 20, 2025

Fixes for grepdiff --status, including tests and documentation.

The -s/--status option has been implemented and working in grepdiff
(inherited from filterdiff) but was not documented in the help text.

The help text previously only mentioned it for lsdiff:
  -s, --status (lsdiff)

Updated to include grepdiff and clarify the status indicators:
  -s, --status (lsdiff, grepdiff)
  show file additions (+), removals (-), and modifications (!)

This matches the documentation in grepdiff(1) man page and brings the
help text in sync with the actual functionality.

Note: The legacy filterdiff implementation has a bug where grepdiff mode
shows '!' for all files instead of the correct +/-/! indicators. This
will be addressed separately. The help text documents the correct,
intended behavior.

Assisted-by: Claude Code
This test currently has incorrect expected output - it expects '!' for
all matching files, but according to the grepdiff documentation, the
-s/--status flag should show:
  + for file additions
  - for file removals
  ! for file modifications

The next commit will fix the test expectations to match the documented
behavior.

Assisted-by: Claude Code
The previous test expected '!' for all matching files, but this is
incorrect according to the grepdiff(1) documentation.

The -s/--status flag should show:
  + for file additions (old file is /dev/null)
  - for file removals (new file is /dev/null)
  ! for file modifications (both files exist)

This matches the behavior documented for both grepdiff and lsdiff.

The legacy filterdiff implementation in --grep mode has a bug where it
always shows '!' regardless of the actual file operation. This test now
correctly verifies the documented behavior.

The test now comprehensively checks all three status indicators:
- First test (pattern 'content'): verifies +, -, and !
- Second test (pattern 'new'): verifies ! for modifications
- Third test (with --empty-files-as-absent): verifies that empty files
  with only additions are treated as new files and show +

Note: The implementation does not yet pass these tests. The fixes will
come in a later commit.

Assisted-by: Claude Code
The grepdiff --status flag was not working correctly, particularly
with --empty-files-as-absent. The issue was that status needed to
be updated after empty file processing but before filename display.

This commit refactors the code to pass status by pointer to the
diff processing functions (do_unified, do_context, do_git_diff_no_hunks),
allowing them to update the status value at the correct time.

Changes:
- Modified function signatures to accept char *status instead of char status
- Added status update logic after empty file processing in each function
- Updated all callers to pass &status instead of status
- Removed duplicate status update logic that was previously done after
  the functions returned

This ensures grepdiff -s displays the correct status (+/-/!) for all
file types, including:
- New files (show +)
- Deleted files (show -)
- Modified files (show !)
- Empty files when --empty-files-as-absent is used

All 187 tests pass.

Assisted-by: Claude Code
@codecov
Copy link

codecov bot commented Oct 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.55%. Comparing base (9d2a83f) to head (517a615).
⚠️ Report is 4 commits behind head on 0.4.x.

Additional details and impacted files
@@            Coverage Diff             @@
##            0.4.x     #150      +/-   ##
==========================================
+ Coverage   83.50%   83.55%   +0.04%     
==========================================
  Files           5        5              
  Lines        4159     4171      +12     
  Branches      985      989       +4     
==========================================
+ Hits         3473     3485      +12     
  Misses        686      686              
Flag Coverage Δ
unittests 83.55% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@twaugh twaugh changed the title Grepdiff status Fixes for grepdiff --status Oct 20, 2025
@twaugh twaugh merged commit 968d881 into 0.4.x Oct 20, 2025
7 checks passed
@twaugh twaugh deleted the grepdiff-status branch October 20, 2025 14:24
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