Fix git grep -l replacing first hyphen with colon in filenames#2089
Open
cjpeterein wants to merge 2 commits intodandavison:mainfrom
Open
Fix git grep -l replacing first hyphen with colon in filenames#2089cjpeterein wants to merge 2 commits intodandavison:mainfrom
cjpeterein wants to merge 2 commits intodandavison:mainfrom
Conversation
When git grep runs with -l/-L/--files-with-matches/--files-without-match, output contains only filenames without line numbers or code. The grep parser's WithoutSeparatorCharacters regex incorrectly matched hyphens in filenames as separators, causing "my-file.rs" to become "my:file.rs". Skip grep line parsing entirely when these filename-only flags are detected. Fixes dandavison#1674 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
dandavison
reviewed
Jan 22, 2026
Existing tests (test_parse_grep_match, test_parse_grep_n_match) already cover parsing grep output with hyphenated filenames, so the additional test_git_grep_n_still_parses_hyphenated_filenames was redundant. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix for issue #1674:
git grep -loutput incorrectly replaces the first hyphen in filenames with a colon (e.g.,my-file.rsbecomesmy:file.rs).git grepis running with filename-only output flags (-l,-L,--files-with-matches,--files-without-match)Problem
When running
git grep -l "pattern" | delta, filenames containing hyphens are corrupted:Root cause: The
WithoutSeparatorCharactersregex inparse_grep_line()excludes hyphens from the file path character class. For inputmy-file.rs(with no line number or code content), it matches:my(stops at hyphen)-(the hyphen from the filename)file.rsWhen the separator is replaced with the default
:, the filename becomesmy:file.rs.Solution
Detect filename-only output mode by checking for
-l/-L/--files-with-matches/--files-without-matchflags in the calling process command line. When detected, returnNonefromparse_grep_line()so the line passes through unchanged.Alternatives Considered
Option B: Improve regex to require content after separator
Modify the
WithoutSeparatorCharactersregex to require actual code content after the separator, not just a file extension pattern.Ruled out because:
test_parse_grep_n_match_file_name_with_dashes_and_no_extension) demonstrates this is a known hard problem-loutput simply isn't grep output formatOption C: Validate parsed path exists on filesystem
After parsing, check if the extracted file path actually exists before accepting the parse result.
Ruled out because:
Test Plan
test_parse_grep_filename_only_output_with_hyphen- verifies filenames with hyphens returnNonewhen-l,-L,--files-with-matches, or--files-without-matchflags are presenttest_parse_grep_regular_output_with_hyphen_still_works- verifies regular grep output with line numbers still parses correctlygit grep -l "pattern" | deltapreserves hyphenated filenamesFixes #1674
🤖 Generated with Claude Code