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: redirect.github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:89ecaf7a-7577-7877-cbf9-a80b90f65231 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | ADCE:1B0FCA:5366F6:72F13B:6A62718C |
| html-safe-nonce | 35d79ae19da2f78355647a47afc5aa49e6e052874949145d4128ebe835249d89 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRENFOjFCMEZDQTo1MzY2RjY6NzJGMTNCOjZBNjI3MThDIiwidmlzaXRvcl9pZCI6IjM5NzE5MTMxODkzNTgyMDMyNzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9b9b4e8ae702cac7be850cdefd13cebb381eb90bb67cd271d4ee38722674248e |
| 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 | 838e87bd0e4f5415707a930bc14e89e382dc2ea046e50ff575252eb2f2cb06a2 |
| 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 | f0081192f88523d2bf4cfdf22bb3e138affc4cd1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width