Skip to content

Conversation

@twaugh
Copy link
Owner

@twaugh twaugh commented Oct 20, 2025

Actually run the grepdiff-status test, and also properly fix the code.

The --empty-files-as-absent option was documented for lsdiff but not
properly supported or documented for grepdiff. This option is useful
with grepdiff -s/--status to correctly identify file additions vs
modifications when files have empty old versions.

For grepdiff, -E already means --extended-regexp, so the short form
cannot be used. This commit makes --empty-files-as-absent available
as a long option only for grepdiff.

Changes:
- Updated help text to show --empty-files-as-absent for grepdiff
  (long form only, since -E means --extended-regexp)
- Updated help text for lsdiff to show -E, --empty-files-as-absent
- Changed option code from 'E' to '1000 + E' to avoid conflict with
  the -E short option for --extended-regexp
- Added case handler for long form option in grepdiff mode
- Updated man page documentation for both lsdiff and grepdiff sections
  with clearer descriptions and examples
- Documented --empty-files-as-removed as an alias (still accepted but
  not shown in help text)

All 188 tests pass (grepdiff-status test not yet added to TESTS).

Assisted-by: Claude Code
This test verifies that grepdiff -s/--status correctly shows:
  + for file additions (old file is /dev/null)
  - for file removals (new file is /dev/null)
  ! for file modifications (both files exist)

The test also verifies that --empty-files-as-absent works correctly
with -s to treat files with empty old versions as additions rather
than modifications.

The test currently fails - it documents the correct expected behavior
that needs to be implemented.

Assisted-by: Claude Code
The grepdiff -s option was incorrectly showing '!' (modification) for
all matching files, regardless of whether they were additions,
deletions, or modifications.

The issue was that grepdiff calls display_filename() from inside
do_unified() and do_context() when it finds a matching line, but the
status variable was always initialized to '!' and never updated based
on file existence.

This fix calculates the correct status (+/-/!) inside do_unified() and
do_context() just before calling display_filename(), using:
- orig_file_exists/new_file_exists to check if files exist
- orig_is_empty/new_is_empty to check for empty files when
  --empty-files-as-absent is used

The fix applies to both unified and context diff formats.

All 194 tests pass (188 pass + 6 expected failures).

Assisted-by: Claude Code
@codecov
Copy link

codecov bot commented Oct 20, 2025

Codecov Report

❌ Patch coverage is 97.61905% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.60%. Comparing base (968d881) to head (68429ac).
⚠️ Report is 5 commits behind head on 0.4.x.

Files with missing lines Patch % Lines
src/filterdiff.c 97.61% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            0.4.x     #152      +/-   ##
==========================================
+ Coverage   83.55%   83.60%   +0.05%     
==========================================
  Files           5        5              
  Lines        4171     4190      +19     
  Branches      989      995       +6     
==========================================
+ Hits         3485     3503      +18     
- Misses        686      687       +1     
Flag Coverage Δ
unittests 83.60% <97.61%> (+0.05%) ⬆️

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.

Expanded the grepdiff-status test to cover additional code paths:

1. File deletion with --empty-files-as-absent: Tests when the new file
   is empty and should be treated as deleted (displays -)

2. Context diff format: Tests grepdiff -s with context diff format
   (*** / --- style) to verify correct status display for additions,
   deletions, and modifications

3. Context diff with --empty-files-as-absent: Tests empty file detection
   in context diff format

These additional test cases ensure complete coverage of the status
calculation logic in both do_unified() and do_context() functions,
including the empty file handling branches.

All 194 tests pass (188 pass + 6 expected failures).

Assisted-by: Claude Code
@twaugh twaugh merged commit e8034e4 into 0.4.x Oct 20, 2025
7 checks passed
@twaugh twaugh deleted the grepdiff-status branch October 20, 2025 16:37
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