Skip to content

Commit 86d0f88

Browse files
codexByron
authored andcommitted
fix(gix): use Git's dirty check for embedded repositories
Git 2.54's raw diff ignores a file that is only untracked inside an embedded gitlink without a .gitmodules entry. GixPython 0.4.0 reports that checkout as dirty. The native submodule status identifies embedded repositories, so use the existing Git path when one is reported modified. Let Git apply the diff ignore policy. The status tests verify untracked and tracked checkout changes for both object formats, alongside the existing configured submodule and worktree cases. All ten focused checks passed with Gix. Agent-Model: unknown
1 parent d9c5286 commit 86d0f88

4 files changed

Lines changed: 32 additions & 4 deletions

File tree

‎doc/gix-backend.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ and predate the current fallback; they do not establish native coverage.
410410
| Selected `set_object` / reference deletion, `update_ref` | Native ref edits with GitPython's existing validation | Strict create/CAS, branch-target validation, symbolic aliases other than HEAD, symbolic detachment, active-branch HEAD log, unchanged targets and log-message cleanup; GIX-9/10/21/24 |
411411
| Tree/commit `Diffable.diff` | Raw change records and unambiguous exact renames | Patches, paths, index/worktree/root diff, inexact/ambiguous renames; GIX-11 |
412412
| `Commit.stats` | Native Myers line counts, binary counts, first-parent tree comparison | Diff attributes, other algorithms, gitlinks, non-ASCII or quoted filenames, large blobs; GIX-2/18 |
413-
| `Repo.is_dirty` | Index/tree/worktree status, configured submodule checks and pathspecs | Custom/sparse indexes and non-root command directories |
413+
| `Repo.is_dirty` | Index/tree/worktree status, configured submodule checks and pathspecs | Custom/sparse indexes, non-root command directories and embedded worktree changes (GIX-40) |
414414
| `Repo.untracked_files` | Native directory walk | Extra status options and non-root command directories |
415415
| `Repo.ignored` | Native excludes with tracked-file suppression | Symlink/submodule traversal, unsupported path normalization, and unavailable path metadata |
416416

@@ -1013,6 +1013,7 @@ identify the historical fixture where needed.
10131013
| GIX-37 | Bug (open) | On macOS with Git 2.54.0 and GixPython 0.3.0 or 0.4.0, create a linear history `A <- B <- C` with `HEAD` at `C` and write `B`'s full SHA-1 followed by a space and newline to `.git/shallow`. `git rev-list --skip=1 HEAD` returns only `B` and stops at the shallow boundary. `Repository.rev_walk([repo.head_id()]).all()` instead raises a `gix.Error` when consumed: `gix-shallow` treats the trailing space as a 41st hexadecimal character. | Match Git's shallow-file parsing in Gitoxide. `Commit.iter_parents(first_parent=False)` keeps the existing CLI fallback in `_backend.history()` and returns `B` with or without `max_count=1`. An explicitly native `first_parent=True` walk still exposes the parsing mismatch, which also occurs through `Commit.iter_items(..., first_parent=True, skip=1)`. |
10141014
| GIX-38 | Bug (open) | With Git 2.54.0 and GixPython 0.4.0, the `commit.sh short-offset` fixture stores `1112591163 +020` in an identity. `git show -s --format=%ad --date=raw` reports `1112591163 +0020`, while `Commit.author()` reports an offset of zero. A separate probe with `+0299` preserves that spelling in Git but renders as `+0339` from the native offset in seconds. | Expose Git-compatible interpretation of short offsets and a way to preserve the stored offset spelling. `object_metadata()` accepts native dates when their formatted prefix matches the raw identity and otherwise keeps the existing CLI fallback. `test_deserialization_short_offset_matches_git` verifies the fallback returns the 20-minute offset. |
10151015
| GIX-39 | Bug (open) | On Git 2.54.0, `git rev-parse --verify HEAD@{never}` rejects the date. GixPython 0.4.0's `Repository.rev_parse_single()` returns the oldest commit. With reflog entries 80, 52, 49, 40, 3 and 0 hours old, Git also selects the 80-hour entry for `HEAD@{2days3hours}`, while Gix selects the 52-hour entry. | Match Git's approxidate grammar and invalid-date handling. `_check_revision_grammar()` retains CLI for textual selectors. `test_rev_parse_reflog_selectors` covers a rejected date, an accepted date and ordinary reflog selectors. |
1016+
| GIX-40 | Bug (open) | With Git 2.54.0 and GixPython 0.4.0, `gix-backend.sh embedded_status_uses_git_diff_policy` tracks a gitlink without a `.gitmodules` entry. An untracked file in its checkout leaves `git diff --raw` empty, but native configured status reports a `SubmoduleModification` with `superproject_configuration` false. Both report changes to tracked files in the embedded checkout. The fixture covers SHA-1 and SHA-256. | Expose Git's diff ignore policy for embedded repositories. `Repo.is_dirty()` uses Git when native worktree status reports a modification in an embedded repository. |
10161017

10171018
GIX-14 also covers configured worktree symlink resolution. On macOS with
10181019
GixPython 0.3.0, CPython 3.12.14 and Git 2.54.0, set a submodule's

‎git/_backend.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,15 +542,22 @@ def is_dirty(command: Any, index: bool, working_tree: bool, untracked: bool, sub
542542
for item in entries:
543543
if item.summary() is None:
544544
continue
545+
details = item.details
545546
if item.kind == "TreeIndex":
546-
if index and (submodules or item.details["entry_mode"] != 0o160000):
547+
if index and (submodules or details["entry_mode"] != 0o160000):
547548
dirty = True
548549
break
549-
elif item.details["kind"] == "DirectoryContents":
550-
if untracked and item.details["entry"]["status"] == "Untracked":
550+
elif details["kind"] == "DirectoryContents":
551+
if untracked and details["entry"]["status"] == "Untracked":
551552
dirty = True
552553
break
553554
elif working_tree:
555+
change = details.get("status", {})
556+
if (
557+
change.get("change") == "SubmoduleModification"
558+
and not change["status"].state["superproject_configuration"]
559+
):
560+
raise _Unsupported("embedded repository diff policy (GIX-40)")
554561
dirty = True
555562
break
556563
except _Unsupported as exc:

‎test/test_gix_backend.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,16 @@ def test_native_status_tracks_submodule_dirtiness(repo):
741741
assert dirty == [repo.is_dirty(**option) for option in options]
742742

743743

744+
@pytest.mark.parametrize("target", ["untracked", "file"])
745+
def test_embedded_status_uses_git_diff_policy(repo, target):
746+
expected = target == "file"
747+
assert bool(repo.git.diff("--raw")) == expected
748+
before = _backend.statistics()
749+
assert repo.is_dirty() == expected
750+
key = ("Repo.is_dirty", "CLI: embedded repository diff policy (GIX-40)")
751+
assert _backend.statistics().get(key, 0) == before.get(key, 0) + 1
752+
753+
744754
@pytest.mark.parametrize("error", [OSError(22, "Invalid filename"), PermissionError(13, "Permission denied")])
745755
def test_ignore_metadata_errors_retain_cli(error):
746756
with fixture_repo("repo.sh", "ignore-verbatim") as repo:

‎tests/fixtures/gix-backend.sh‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ native_status_tracks_submodule_dirtiness)
163163
git -C repo commit -qm 'add submodule'
164164
printf modified > repo/module/file
165165
;;
166+
embedded_status_uses_git_diff_policy)
167+
git init -q --object-format="$hash" repo/module
168+
printf initial > repo/module/file
169+
git -C repo/module add file
170+
git -C repo/module commit -qm initial
171+
oid=$(git -C repo/module rev-parse HEAD)
172+
git -C repo update-index --add --cacheinfo "160000,$oid,module"
173+
git -C repo commit -qm 'track embedded repository'
174+
printf changed > "repo/module/$extra"
175+
;;
166176
native_commit_statistics_match_cli)
167177
cd repo
168178
git config diff.algorithm myers

0 commit comments

Comments
 (0)