Let is_dirty handle unborn HEADs#2589
Merged
Merged
Conversation
Repository::is_dirty() called head_tree_id() before comparing HEAD to the index, which made freshly initialized repositories fail with an unborn-HEAD error before the dirty check could complete. Git reference: git describe --dirty uses the equivalent of git diff-index --quiet HEAD -- in builtin/describe.c; in an unborn repository, git diff-index HEAD reports bad revision, so gix uses its existing empty-tree fallback for this otherwise undefined case. Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
…ications. Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
5b0fda3 to
3406b1d
Compare
There was a problem hiding this comment.
Pull request overview
This PR adjusts gix::Repository::is_dirty() to behave sensibly when HEAD is unborn by using the repository’s existing empty-tree fallback, aligning behavior with how other status code paths already handle this case. It also extends the status fixture set and adds regression tests to ensure unborn repositories no longer cause is_dirty() to error while preserving the documented behavior that untracked files do not affect dirtiness.
Changes:
- Use
head_tree_id_or_empty()inRepository::is_dirty()to avoid errors on unbornHEAD. - Add fixtures and tests for unborn-
HEADscenarios (untracked-only and index-added files). - Extend the status fixture generator script with a new
added-unbornrepository.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| gix/src/status/mod.rs | Switches is_dirty() to use the empty-tree fallback for unborn HEAD. |
| gix/tests/gix/status.rs | Adds regression tests covering unborn HEAD behavior for status and is_dirty. |
| gix/tests/fixtures/make_status_repos.sh | Adds a new added-unborn fixture repository used by the new tests. |
Build the `gix-filter` `arrow` example through a shared test helper and copy it into each test process' target temp dir before use. This avoids races where parallel Cargo invocations replace or remove the shared `target/debug/examples/arrow` binary while another test is spawning it. Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tasks
Summary
Repository::is_dirty()use the existing empty-tree fallback whenHEADis unbornis_dirty()dirtyRefs #2587
Git reference
git describe --dirtyuses the equivalent ofgit diff-index --quiet HEAD --inbuiltin/describe.c. In an unborn repository,git diff-index HEADreportsbad revision, so this patch follows gix's existinghead_tree_id_or_empty()status behavior and compares against the empty tree for this undefined case.Validation
cargo test -p gix --test gix status::is_dirty::unborn_head_is_not_an_errorcargo test -p gix --test gix status::is_dirtycargo test -p gix --test gix statuscargo fmt --allcodex review --uncommittedcodex review --commit 5b0fda373dcf8df44750b65ab3343c8cf9d23189Disclosure
This draft PR was created by Codex on behalf of Byron. Byron will review it before it is marked ready.