Uh oh!
There was an error while loading. Please reload this page.
Support index diffs against the empty tree - #2155
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds IndexFile.diff(NULL_TREE) support so callers can diff the index against an “empty tree” (useful for initial index contents), and introduces a regression test to validate expected diff output.
Changes:
- Extends
IndexFile.diff()to accept and handleNULL_TREEas theotherdiff target. - Implements a custom
git diff --cached <empty-tree>invocation to produce raw/patch output for the NULL_TREE case. - Adds a test covering initial index diffing against
NULL_TREE, including path filtering and patch creation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| test/test_index.py | Adds coverage for diffing an initial index against NULL_TREE and verifying raw + patch output. |
| git/index/base.py | Implements IndexFile.diff(NULL_TREE) by invoking git diff --cached against the empty-tree SHA. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assisted-by: OpenAI GPT-5
4508774 to
3895682CompareAssisted-by: ChatGPT
puneetdixit200
commented
May 23, 2026
AI agent on behalf of Puneet: pushed Verified:
|
Co-authored-by: OpenAI Codex <codex@openai.com>
Co-authored-by: OpenAI Codex <codex@openai.com>
Match the AutoInterrupt wait signature so diff parser tests can pass preserved stderr through finalize_process. Assisted-by: OpenAI GPT-5
Byron
commented
May 27, 2026
It seems bots are running around and fixing to dos automatically. And in a way, it's fine. This seems to be addressing the TODO legitimately and the bots already hashed it out, so I'll just try rolling with it. The biggest problem GitPython has is that I don't think it has a human who knows what good Python is supposed to be like these days. So, agents will basically rule this place and all I can do is to apply high level quality constraints - better than nothing. |
Uh oh!
There was an error while loading. Please reload this page.
Related to #2025.
IndexFile.diff()is documented as accepting the same targets asDiffable.diff(), includingNULL_TREE, but the index-specific implementation rejectedNULL_TREEbefore it could produce a diff. That leaves no direct API path for inspecting staged entries for an initial commit against the empty tree.This adds explicit
IndexFile.diff(NULL_TREE)handling usinggit diff --cachedagainst the empty tree object. I keptIndexFile.diff(None)as the existing index-vs-working-tree comparison, since that behavior is documented in the quick docs and existing tests.The regression test creates a new repository, stages a file, writes the index, constructs a fresh
IndexFile, and verifies thatindex.diff(NULL_TREE)reports the staged addition whileindex.diff(None)remains empty because the working tree matches the index.Validation:
.venv/bin/python -m pytest --no-cov test/test_index.py::TestIndex::test_index_file_diff_null_tree_with_initial_index -q.venv/bin/python -m ruff check git/index/base.py test/test_index.pyAI assistance disclosure: OpenAI GPT-5 helped draft and check this change; I reviewed the implementation and tests before submitting.