Skip to content

fix(gix): rename empty files in native tree diffs like Git - #2358

Merged
Byron merged 1 commit into
gitpython-developers:mainfrom
Keerthana-64:gix-diff-empty-renames
Nov 24, 2026
Merged

Byron merged 1 commit into
gitpython-developers:mainfrom
Keerthana-64:gix-diff-empty-renames

Conversation

@Keerthana-64

Copy link
Copy Markdown
Contributor

Problem

Gix aur Git backends mein empty file ko rename karne par different results mil rahe the. Git backend mein git diff-tree -r -M --raw rename ko R100 ke roop mein report karta tha, jabki Gix backend ka tree_diff() usi change ko A (add) aur D (delete) ke roop mein report kar raha tha.

Iska reason the ki Gix ke Rewrites mein default track_empty=False hota hai, jo merge-style behavior use karta hai. Jabki Git mein git diff -M ka default behavior --rename-empty hota hai.

Fix: Gix ke Rewrites(percentage=None) mein track_empty=True pass kiya gaya hai, jisse empty file renames bhi Git ke behavior ke according detect hote hain. Python side par koi additional pairing logic add nahi ki gayi hai, aur duplicate blob IDs ab bhi existing ambiguity guard ke through handle hote hain.

Is change ke liye diff.sh empty-rename fixture add kiya gaya hai. Naya test_rename_of_empty_file test change se pehle Gix backend par fail hota tha, lekin change ke baad dono backends par successfully pass hota hai, including R=True configuration ke saath.

CLI backend ke against 18 tree pairs par testing ki gayi, jisme empty aur non-empty file renames, mode changes, symlink/file changes, gitlinks, swaps aur directory moves shamil the. Change se pehle sirf empty file rename wale case mein difference mila, jabki change ke baad sabhi cases mein dono backends ke results match hue.

Testing: test_diff.py CLI backend par successfully pass hota hai. Gix backend par sirf test_native_repository_lifetime_and_refresh ke dono cases fail hote hain, jo is change ke bina bhi missing global Git identity ki wajah se same tarah fail hote hain.

Iske alawa ruff, shellcheck, mypy aur git diff --check successfully pass hote hain.

<!-- agent: Claude -->

On the Gix backend, `Diffable.diff()` between two trees or commits builds
its result in `_backend.tree_diff()`. When the added and deleted blob IDs
pair up unambiguously, the adapter asks Gix for exact rename tracking
with `gix.Rewrites(percentage=None)`. GixPython's `Rewrites` defaults to
`track_empty=False`, the merge-style setting that never pairs empty
blobs, while `git diff -M` (and the CLI backend) defaults to
`--rename-empty` and reports an empty file moved from `a` to `b` as
`R100`.

So for a commit that only renames an empty file (an `__init__.py`, a
`.gitkeep`, a placeholder), the CLI backend returned one `R` diff with
`renamed_file` set, and the Gix backend returned an `A` diff for the new
path and a `D` diff for the old one. The same happened with `R=True`.
Code that follows renames through `rename_from`/`rename_to`, or that
treats additions and deletions differently from renames, saw a different
history depending on the backend.

The adapter now passes `track_empty=True`, which is the Gix mode that
matches Git's default for this diff. No pairing is done in Python; the
existing ambiguity guard still sends duplicate blob IDs to Git, so
several empty files added or deleted at once keep using the CLI path.
This is adapter configuration rather than a Gix bug, so no new ledger
entry is added.

Validation on Windows with CPython 3.11, Git 2.56.0 and GixPython 0.3.0
built from source:

- `test_rename_of_empty_file`, using the new `diff.sh empty-rename`
  fixture, fails on the Gix backend before the change (two diffs instead
  of one) and passes on both backends after it.
- A sweep of 18 tree pairs compared against the CLI backend (empty and
  non-empty renames, mode changes, symlink/file and gitlink cases,
  swaps, directory moves, both directions with `R=True`) differed only
  in the empty-rename case before the change and matches in every case
  after it; all pairs without duplicate blob IDs stayed native.
- `test/test_diff.py` passes on the CLI backend (50 passed). On the Gix
  backend, `test_diff.py`, `test_gix_backend.py`,
  `test_cli_process_counts.py` and `test_commit.py` give 193 passed and
  2 failed; the two failures
  (`test_native_repository_lifetime_and_refresh[sha1|sha256]`) fail
  identically without this change because the test machine has no
  global Git identity for its `git commit`.
- `ruff check`, `ruff format --check`, `shellcheck`, `mypy` and
  `git diff --check` pass. The full suite was not run.

Agent-Model: claude-opus-5-5
@Byron
Byron merged commit 58428e3 into gitpython-developers:main Nov 24, 2026
62 of 64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants