Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 986
Support index diffs against the empty tree#2155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Byron
merged 5 commits into
gitpython-developers:main
from
puneetdixit200:fix-initial-index-diffMay 27, 2026
+101
−10
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3895682
Support index diffs against empty tree
fe4b66d
fix: use shared empty tree sha for index diffs
puneetdixit200 da07a64
test: allow alternate bad fetch errors
puneetdixit200 59cc3bb
fix: preserve diff process stderr
puneetdixit200 4de94bc
test: accept stderr in string process adapter
puneetdixit200 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1480,12 +1480,11 @@ def reset( | ||
| return self | ||
| # FIXME: This is documented to accept the same parameters as Diffable.diff, but this | ||
| # does not handle NULL_TREE for `other`. (The suppressed mypy error is about this.) | ||
| def diff( | ||
| self, | ||
| other: Union[ # type: ignore[override] | ||
| other: Union[ | ||
| Literal[git_diff.DiffConstants.INDEX], | ||
| Literal[git_diff.DiffConstants.NULL_TREE], | ||
| "Tree", | ||
| "Commit", | ||
| str, | ||
| @@ -1512,6 +1511,44 @@ def diff( | ||
| if other is self.INDEX: | ||
| return git_diff.DiffIndex() | ||
| if other == git_diff.NULL_TREE or other == git_diff.NULL_TREE_SHA: | ||
| args: List[Union[PathLike, str]] = [ | ||
| "--cached", | ||
| git_diff.NULL_TREE_SHA, | ||
| "--abbrev=40", | ||
| "--full-index", | ||
| ] | ||
| if not any(x in kwargs for x in ("find_renames", "no_renames", "M")): | ||
| args.append("-M") | ||
| if create_patch: | ||
| args.append("-p") | ||
| args.append("--no-ext-diff") | ||
| else: | ||
| args.append("--raw") | ||
| args.append("-z") | ||
| args.append("--no-color") | ||
| if paths is not None and not isinstance(paths, (tuple, list)): | ||
| paths = [paths] | ||
| if paths: | ||
| args.append("--") | ||
| args.extend(paths) | ||
| kwargs["as_process"] = True | ||
| proc = self.repo.git.diff(*args, **kwargs) | ||
| diff_method = ( | ||
| git_diff.Diff._index_from_patch_format if create_patch else git_diff.Diff._index_from_raw_format | ||
| ) | ||
| index = diff_method(self.repo, proc) | ||
| proc.wait() | ||
puneetdixit200 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| return index | ||
| # Index against anything but None is a reverse diff with the respective item. | ||
| # Handle existing -R flags properly. | ||
| # Transform strings to the object so that we can call diff on it. | ||
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
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
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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.