GeezerVison is showing github.com — fix: use shared empty tree sha for index diffs · gitpython-developers/GitPython@fe4b66d
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: git/diff.py +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | # This module is part of GitPython and is released under the | 4 | 4 | # 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/ | 5 | 5 |
| 6 | | -__all__ = ["DiffConstants", "NULL_TREE", "INDEX", "Diffable", "DiffIndex", "Diff"] | | 6 | +__all__ = ["DiffConstants", "NULL_TREE", "NULL_TREE_SHA", "INDEX", "Diffable", "DiffIndex", "Diff"] | 7 | 7 |
| 8 | 8 | import enum | 9 | 9 | import re | @@ -84,6 +84,9 @@ class DiffConstants(enum.Enum): | 84 | 84 | :const:`git.NULL_TREE` and :const:`Diffable.NULL_TREE`. | 85 | 85 | """ | 86 | 86 |
| | 87 | +NULL_TREE_SHA = "4b825dc642cb6eb9a060e54bf8d69288fbee4904" | | 88 | +"""SHA of Git's canonical empty tree object.""" | | 89 | + | 87 | 90 | INDEX: Literal[DiffConstants.INDEX] = DiffConstants.INDEX | 88 | 91 | """Stand-in indicating you want to diff against the index. | 89 | 92 |
| |
Collapse file Copy file name to clipboardExpand all lines: git/index/base.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1511,10 +1511,10 @@ def diff( | 1511 | 1511 | if other is self.INDEX: | 1512 | 1512 | return git_diff.DiffIndex() | 1513 | 1513 |
| 1514 | | - if other is git_diff.NULL_TREE: | | 1514 | + if other == git_diff.NULL_TREE or other == git_diff.NULL_TREE_SHA: | 1515 | 1515 | args: List[Union[PathLike, str]] = [ | 1516 | 1516 | "--cached", | 1517 | | - "4b825dc642cb6eb9a060e54bf8d69288fbee4904", | | 1517 | + git_diff.NULL_TREE_SHA, | 1518 | 1518 | "--abbrev=40", | 1519 | 1519 | "--full-index", | 1520 | 1520 | ] | |
Collapse file Copy file name to clipboardExpand all lines: test/test_index.py +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 24 | 24 | import pytest | 25 | 25 |
| 26 | 26 | from git import BlobFilter, Diff, Git, IndexFile, NULL_TREE, Object, Repo, Tree | | 27 | +from git.diff import NULL_TREE_SHA | 27 | 28 | from git.exc import ( | 28 | 29 | CheckoutError, | 29 | 30 | GitCommandError, | @@ -568,7 +569,7 @@ def test_index_file_diff_null_tree_with_initial_index(self, rw_dir): | 568 | 569 | index.write() | 569 | 570 |
| 570 | 571 | index = IndexFile(repo) | 571 | | - assert not index.diff(None) | | 572 | + self.assertEqual(len(index.diff(None)), 0) | 572 | 573 |
| 573 | 574 | diff = index.diff(NULL_TREE) | 574 | 575 | self.assertEqual(len(diff), 1) | @@ -577,6 +578,7 @@ def test_index_file_diff_null_tree_with_initial_index(self, rw_dir): | 577 | 578 | self.assertEqual(diff[0].b_path, filename) | 578 | 579 |
| 579 | 580 | self.assertEqual(len(index.diff(NULL_TREE, paths=filename)), 1) | | 581 | + self.assertEqual(len(index.diff(NULL_TREE_SHA, paths=filename)), 1) | 580 | 582 | self.assertEqual(len(index.diff(NULL_TREE, paths="missing")), 0) | 581 | 583 |
| 582 | 584 | patch = index.diff(NULL_TREE, create_patch=True) | |
|