2 files changed
@@ -371,7 +371,7 @@ class Diff: | |||
| 371 | 371 | ||
| 372 | 372 | # Precompiled regex. | |
| 373 | 373 | # Note: The path prefixes support both default (a/b) and mnemonicPrefix mode | |
| 374 | - # which can use prefixes like c/ (commit), w/ (worktree), i/ (index), o/ (object) | ||
| 374 | + # which can use prefixes like c/ (commit), w/ (worktree), i/ (index), o/ (object), and h/ (HEAD) | ||
| 375 | 375 | re_header = re.compile( | |
| 376 | 376 | rb""" | |
| 377 | 377 | ^diff[ ]--git | |
@@ -290,28 +290,42 @@ def test_diff_mnemonic_prefix(self): | |||
| 290 | 290 | - w/ for worktree | |
| 291 | 291 | - i/ for index | |
| 292 | 292 | - o/ for object | |
| 293 | + - h/ for HEAD | ||
| 293 | 294 | ||
| 294 | 295 | This addresses issue #2013 where the regex only matched [ab]/ prefixes. | |
| 295 | 296 | """ | |
| 296 | - # Create a diff with mnemonicPrefix-style c/ and w/ prefixes | ||
| 297 | - # Using valid 40-char hex SHAs | ||
| 298 | - diff_mnemonic = b"""diff --git c/.vscode/launch.json w/.vscode/launch.json | ||
| 299 | - index 1234567890abcdef1234567890abcdef12345678..abcdef1234567890abcdef1234567890abcdef12 100644 | ||
| 300 | - --- c/.vscode/launch.json | ||
| 301 | - +++ w/.vscode/launch.json | ||
| 302 | - @@ -1,3 +1,3 @@ | ||
| 303 | - -old content | ||
| 304 | - +new content | ||
| 305 | - """ | ||
| 306 | - diff_proc = StringProcessAdapter(diff_mnemonic) | ||
| 307 | - diffs = Diff._index_from_patch_format(self.rorepo, diff_proc) | ||
| 308 | - | ||
| 309 | - # Should parse successfully (previously would fail or return empty) | ||
| 310 | - self.assertEqual(len(diffs), 1) | ||
| 311 | - diff = diffs[0] | ||
| 312 | - # The path should be extracted correctly (without the c/ or w/ prefix) | ||
| 313 | - self.assertEqual(diff.a_path, ".vscode/launch.json") | ||
| 314 | - self.assertEqual(diff.b_path, ".vscode/launch.json") | ||
| 297 | + # Test all mnemonicPrefix combinations | ||
| 298 | + # Each tuple is (a_prefix, b_prefix) representing different comparison types | ||
| 299 | + prefix_pairs = [ | ||
| 300 | + (b"c/", b"w/"), # commit vs worktree | ||
| 301 | + (b"c/", b"i/"), # commit vs index | ||
| 302 | + (b"i/", b"w/"), # index vs worktree | ||
| 303 | + (b"o/", b"w/"), # object vs worktree | ||
| 304 | + (b"h/", b"i/"), # HEAD vs index | ||
| 305 | + (b"h/", b"w/"), # HEAD vs worktree | ||
| 306 | + ] | ||
| 307 | + | ||
| 308 | + for a_prefix, b_prefix in prefix_pairs: | ||
| 309 | + with self.subTest(a_prefix=a_prefix, b_prefix=b_prefix): | ||
| 310 | + diff_mnemonic = ( | ||
| 311 | + b"diff --git " + a_prefix + b".vscode/launch.json " + b_prefix + b".vscode/launch.json\n" | ||
| 312 | + b"index 1234567890abcdef1234567890abcdef12345678.." | ||
| 313 | + b"abcdef1234567890abcdef1234567890abcdef12 100644\n" | ||
| 314 | + b"--- " + a_prefix + b".vscode/launch.json\n" | ||
| 315 | + b"+++ " + b_prefix + b".vscode/launch.json\n" | ||
| 316 | + b"@@ -1,3 +1,3 @@\n" | ||
| 317 | + b"-old content\n" | ||
| 318 | + b"+new content\n" | ||
| 319 | + ) | ||
| 320 | + diff_proc = StringProcessAdapter(diff_mnemonic) | ||
| 321 | + diffs = Diff._index_from_patch_format(self.rorepo, diff_proc) | ||
| 322 | + | ||
| 323 | + # Should parse successfully (previously would fail or return empty) | ||
| 324 | + self.assertEqual(len(diffs), 1) | ||
| 325 | + diff = diffs[0] | ||
| 326 | + # The path should be extracted correctly (without the prefix) | ||
| 327 | + self.assertEqual(diff.a_path, ".vscode/launch.json") | ||
| 328 | + self.assertEqual(diff.b_path, ".vscode/launch.json") | ||
| 315 | 329 | ||
| 316 | 330 | def test_diff_patch_format(self): | |
| 317 | 331 | # Test all of the 'old' format diffs for completeness - it should at least be | |
0 commit comments