[PR #458] Handle w/ prefix in diff parsing for workdir diffs #485

Closed
opened 2026-03-02 04:13:45 +03:00 by kerem · 0 comments
Owner

Original Pull Request: https://github.com/git-ai-project/git-ai/pull/458

State: closed
Merged: Yes


When git produces commit-to-workdir diffs (e.g., with diff.mnemonicPrefix), it uses w/ instead of b/ as the destination prefix. Add support for parsing both unquoted ("+++ w/") and quoted ('+++ "w/"') path formats in parse_diff_added_lines and parse_diff_added_lines_with_insertions. Add tests covering standard, workdir, quoted, and quoted workdir path formats.

This fixes failures in four of the amend related tests that I was seeing on my macOS machine:

failures:

---- test_amend_with_partially_staged_mixed_content stdout ----

thread 'test_amend_with_partially_staged_mixed_content' (129931499) panicked at tests/repos/test_file.rs:286:21:
Line 4: Expected AI author but got 'Test User'
Expected: ExpectedLine { contents: "// AI addition 2", author_type: Ai }
Actual content: "// AI addition 2"
Full blame output:
ee6bbde (Test User 2026-02-04 12:39:46 -0800 1) human line 1
ee6bbde (Test User 2026-02-04 12:39:46 -0800 2) human line 2
ee6bbde (mock_ai   2026-02-04 12:39:46 -0800 3) // AI addition 1
53d3d5d (Test User 2026-02-04 12:39:49 -0800 4) // AI addition 2
ee6bbde (mock_ai   2026-02-04 12:39:46 -0800 5) human end

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- test_amend_with_unstaged_middle_section stdout ----

thread 'test_amend_with_unstaged_middle_section' (129931501) panicked at tests/repos/test_file.rs:286:21:
Line 4: Expected AI author but got 'Test User'
Expected: ExpectedLine { contents: "// AI section 2 line 1", author_type: Ai }
Actual content: "// AI section 2 line 1"
Full blame output:
580ad8c (Test User 2026-02-04 12:39:46 -0800 1) // File header
580ad8c (mock_ai   2026-02-04 12:39:46 -0800 2) // AI section 1 line 1
580ad8c (mock_ai   2026-02-04 12:39:46 -0800 3) // AI section 1 line 2
11aa72a (Test User 2026-02-04 12:39:50 -0800 4) // AI section 2 line 1
11aa72a (Test User 2026-02-04 12:39:50 -0800 5) // AI section 2 line 2
580ad8c (mock_ai   2026-02-04 12:39:46 -0800 6) // AI section 3 line 1
580ad8c (mock_ai   2026-02-04 12:39:46 -0800 7) // AI section 3 line 2


---- test_amend_add_lines_at_top stdout ----

thread 'test_amend_add_lines_at_top' (129931493) panicked at tests/repos/test_file.rs:286:21:
Line 1: Expected AI author but got 'Test User'
Expected: ExpectedLine { contents: "// AI added line 1", author_type: Ai }
Actual content: "// AI added line 1"
Full blame output:
9a17f40 (Test User 2026-02-04 12:39:50 -0800 1) // AI added line 1
9a17f40 (Test User 2026-02-04 12:39:50 -0800 2) // AI added line 2
3085013 (mock_ai   2026-02-04 12:39:46 -0800 3) line 1
3085013 (mock_ai   2026-02-04 12:39:46 -0800 4) line 2
3085013 (Test User 2026-02-04 12:39:46 -0800 5) line 3
3085013 (Test User 2026-02-04 12:39:46 -0800 6) line 4
3085013 (Test User 2026-02-04 12:39:46 -0800 7) line 5


---- test_amend_with_partially_staged_ai_file stdout ----

thread 'test_amend_with_partially_staged_ai_file' (129931498) panicked at tests/repos/test_file.rs:286:21:
Line 5: Expected AI author but got 'Test User'
Expected: ExpectedLine { contents: "// AI line 4", author_type: Ai }
Actual content: "// AI line 4"
Full blame output:
fae450f (Test User 2026-02-04 12:39:46 -0800 1) // Initial line
fae450f (mock_ai   2026-02-04 12:39:46 -0800 2) // AI line 1
fae450f (mock_ai   2026-02-04 12:39:46 -0800 3) // AI line 2
fae450f (mock_ai   2026-02-04 12:39:46 -0800 4) // AI line 3
200c74e (Test User 2026-02-04 12:39:51 -0800 5) // AI line 4
200c74e (Test User 2026-02-04 12:39:51 -0800 6) // AI line 5
200c74e (Test User 2026-02-04 12:39:51 -0800 7) // AI line 6



failures:
    test_amend_add_lines_at_top
    test_amend_with_partially_staged_ai_file
    test_amend_with_partially_staged_mixed_content
    test_amend_with_unstaged_middle_section

test result: FAILED. 6 passed; 4 failed; 0 ignored; 0 measured; 0 filtered out; finished in 7.58s

Open with Devin
**Original Pull Request:** https://github.com/git-ai-project/git-ai/pull/458 **State:** closed **Merged:** Yes --- When git produces commit-to-workdir diffs (e.g., with diff.mnemonicPrefix), it uses w/ instead of b/ as the destination prefix. Add support for parsing both unquoted ("+++ w/") and quoted ('+++ "w/"') path formats in parse_diff_added_lines and parse_diff_added_lines_with_insertions. Add tests covering standard, workdir, quoted, and quoted workdir path formats. This fixes failures in four of the `amend` related tests that I was seeing on my macOS machine: ``` failures: ---- test_amend_with_partially_staged_mixed_content stdout ---- thread 'test_amend_with_partially_staged_mixed_content' (129931499) panicked at tests/repos/test_file.rs:286:21: Line 4: Expected AI author but got 'Test User' Expected: ExpectedLine { contents: "// AI addition 2", author_type: Ai } Actual content: "// AI addition 2" Full blame output: ee6bbde (Test User 2026-02-04 12:39:46 -0800 1) human line 1 ee6bbde (Test User 2026-02-04 12:39:46 -0800 2) human line 2 ee6bbde (mock_ai 2026-02-04 12:39:46 -0800 3) // AI addition 1 53d3d5d (Test User 2026-02-04 12:39:49 -0800 4) // AI addition 2 ee6bbde (mock_ai 2026-02-04 12:39:46 -0800 5) human end note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ---- test_amend_with_unstaged_middle_section stdout ---- thread 'test_amend_with_unstaged_middle_section' (129931501) panicked at tests/repos/test_file.rs:286:21: Line 4: Expected AI author but got 'Test User' Expected: ExpectedLine { contents: "// AI section 2 line 1", author_type: Ai } Actual content: "// AI section 2 line 1" Full blame output: 580ad8c (Test User 2026-02-04 12:39:46 -0800 1) // File header 580ad8c (mock_ai 2026-02-04 12:39:46 -0800 2) // AI section 1 line 1 580ad8c (mock_ai 2026-02-04 12:39:46 -0800 3) // AI section 1 line 2 11aa72a (Test User 2026-02-04 12:39:50 -0800 4) // AI section 2 line 1 11aa72a (Test User 2026-02-04 12:39:50 -0800 5) // AI section 2 line 2 580ad8c (mock_ai 2026-02-04 12:39:46 -0800 6) // AI section 3 line 1 580ad8c (mock_ai 2026-02-04 12:39:46 -0800 7) // AI section 3 line 2 ---- test_amend_add_lines_at_top stdout ---- thread 'test_amend_add_lines_at_top' (129931493) panicked at tests/repos/test_file.rs:286:21: Line 1: Expected AI author but got 'Test User' Expected: ExpectedLine { contents: "// AI added line 1", author_type: Ai } Actual content: "// AI added line 1" Full blame output: 9a17f40 (Test User 2026-02-04 12:39:50 -0800 1) // AI added line 1 9a17f40 (Test User 2026-02-04 12:39:50 -0800 2) // AI added line 2 3085013 (mock_ai 2026-02-04 12:39:46 -0800 3) line 1 3085013 (mock_ai 2026-02-04 12:39:46 -0800 4) line 2 3085013 (Test User 2026-02-04 12:39:46 -0800 5) line 3 3085013 (Test User 2026-02-04 12:39:46 -0800 6) line 4 3085013 (Test User 2026-02-04 12:39:46 -0800 7) line 5 ---- test_amend_with_partially_staged_ai_file stdout ---- thread 'test_amend_with_partially_staged_ai_file' (129931498) panicked at tests/repos/test_file.rs:286:21: Line 5: Expected AI author but got 'Test User' Expected: ExpectedLine { contents: "// AI line 4", author_type: Ai } Actual content: "// AI line 4" Full blame output: fae450f (Test User 2026-02-04 12:39:46 -0800 1) // Initial line fae450f (mock_ai 2026-02-04 12:39:46 -0800 2) // AI line 1 fae450f (mock_ai 2026-02-04 12:39:46 -0800 3) // AI line 2 fae450f (mock_ai 2026-02-04 12:39:46 -0800 4) // AI line 3 200c74e (Test User 2026-02-04 12:39:51 -0800 5) // AI line 4 200c74e (Test User 2026-02-04 12:39:51 -0800 6) // AI line 5 200c74e (Test User 2026-02-04 12:39:51 -0800 7) // AI line 6 failures: test_amend_add_lines_at_top test_amend_with_partially_staged_ai_file test_amend_with_partially_staged_mixed_content test_amend_with_unstaged_middle_section test result: FAILED. 6 passed; 4 failed; 0 ignored; 0 measured; 0 filtered out; finished in 7.58s ``` <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/git-ai-project/git-ai/pull/458" target="_blank"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1"> <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin"> </picture> </a> <!-- devin-review-badge-end -->
kerem 2026-03-02 04:13:45 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/git-ai#485
No description provided.