Title: Support index diffs against the empty tree by puneetdixit200 · Pull Request #2155 · gitpython-developers/GitPython · GitHub
Open Graph Title: Support index diffs against the empty tree by puneetdixit200 · Pull Request #2155 · gitpython-developers/GitPython
X Title: Support index diffs against the empty tree by puneetdixit200 · Pull Request #2155 · gitpython-developers/GitPython
Description: Related to #2025. IndexFile.diff() is documented as accepting the same targets as Diffable.diff(), including NULL_TREE, but the index-specific implementation rejected NULL_TREE before 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 using git diff --cached against the empty tree object. I kept IndexFile.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 that index.diff(NULL_TREE) reports the staged addition while index.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.py AI assistance disclosure: OpenAI GPT-5 helped draft and check this change; I reviewed the implementation and tests before submitting.
Open Graph Description: Related to #2025. IndexFile.diff() is documented as accepting the same targets as Diffable.diff(), including NULL_TREE, but the index-specific implementation rejected NULL_TREE before it could prod...
X Description: Related to #2025. IndexFile.diff() is documented as accepting the same targets as Diffable.diff(), including NULL_TREE, but the index-specific implementation rejected NULL_TREE before it could prod...
Opengraph URL: https://github.com/gitpython-developers/GitPython/pull/2155
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:185c22d3-c825-0785-5843-e254a64d3804 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8474:93A86:17B520A:1FE2161:6A596937 |
| html-safe-nonce | 53bcd48d6d5686ff281de58d11bf9063d70dddc724816c4b9a26415a6ef05c32 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NDc0OjkzQTg2OjE3QjUyMEE6MUZFMjE2MTo2QTU5NjkzNyIsInZpc2l0b3JfaWQiOiI2MDk4NzI1ODg4Nzg0NzM1MjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 04298589f0a4c0b6de20abc8e744531fe20fa27f3a35fe6957b466a1801213be |
| hovercard-subject-tag | pull_request:3721833410 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/gitpython-developers/GitPython/pull/2155/files |
| twitter:image | https://avatars.githubusercontent.com/u/236133619?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/236133619?s=400&v=4 |
| og:image:alt | Related to #2025. IndexFile.diff() is documented as accepting the same targets as Diffable.diff(), including NULL_TREE, but the index-specific implementation rejected NULL_TREE before it could prod... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | a540949572872b935b393b36db38922db390ae71c859537d741b8f3eb7e545b5 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git |
| octolytics-dimension-user_id | 503709 |
| octolytics-dimension-user_login | gitpython-developers |
| octolytics-dimension-repository_id | 1126087 |
| octolytics-dimension-repository_nwo | gitpython-developers/GitPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1126087 |
| octolytics-dimension-repository_network_root_nwo | gitpython-developers/GitPython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4aa391d605ba491481565840251a4b0fec3f4807 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width