|
11 | 11 |
|
12 | 12 | from git.cmd import Git, handle_process_output |
13 | 13 | from git.compat import defenc |
| 14 | +from git.objects.base import IndexObject |
14 | 15 | from git.objects.blob import Blob |
15 | 16 | from git.objects.util import mode_str_to_int |
16 | 17 | from git.util import finalize_process, hex_to_bin |
|
35 | 36 | if TYPE_CHECKING: |
36 | 37 | from subprocess import Popen |
37 | 38 |
|
38 | | - from git.objects.base import IndexObject |
39 | 39 | from git.objects.commit import Commit |
40 | 40 | from git.objects.tree import Tree |
41 | 41 | from git.repo.base import Repo |
@@ -378,6 +378,10 @@ class Diff: |
378 | 378 | Diffs keep information about the changed blob objects, the file mode, renames, |
379 | 379 | deletions and new files. |
380 | 380 |
|
| 381 | + For submodule changes, ``a_blob`` and ``b_blob`` are |
| 382 | + :class:`~git.objects.base.IndexObject` instances whose SHAs refer to commits in |
| 383 | + the submodule repository. |
| 384 | +
|
381 | 385 | There are a few cases where ``None`` has to be expected as member variable value: |
382 | 386 |
|
383 | 387 | New File:: |
@@ -481,17 +485,22 @@ def __init__( |
481 | 485 | repo = submodule.module() |
482 | 486 | break |
483 | 487 |
|
| 488 | + # Gitlinks reference commits; generic index objects preserve their path and mode. |
484 | 489 | self.a_blob: Union["IndexObject", None] |
485 | 490 | if a_blob_id is None or a_blob_id == self.NULL_HEX_SHA: |
486 | 491 | self.a_blob = None |
487 | 492 | else: |
488 | | - self.a_blob = Blob(repo, hex_to_bin(a_blob_id), mode=self.a_mode, path=self.a_path) |
| 493 | + self.a_blob = (IndexObject if self.a_mode == 0o160000 else Blob)( |
| 494 | + repo, hex_to_bin(a_blob_id), mode=self.a_mode, path=self.a_path |
| 495 | + ) |
489 | 496 |
|
490 | 497 | self.b_blob: Union["IndexObject", None] |
491 | 498 | if b_blob_id is None or b_blob_id == self.NULL_HEX_SHA: |
492 | 499 | self.b_blob = None |
493 | 500 | else: |
494 | | - self.b_blob = Blob(repo, hex_to_bin(b_blob_id), mode=self.b_mode, path=self.b_path) |
| 501 | + self.b_blob = (IndexObject if self.b_mode == 0o160000 else Blob)( |
| 502 | + repo, hex_to_bin(b_blob_id), mode=self.b_mode, path=self.b_path |
| 503 | + ) |
495 | 504 |
|
496 | 505 | self.new_file: bool = new_file |
497 | 506 | self.deleted_file: bool = deleted_file |
|
0 commit comments