Skip to content

Let is_dirty handle unborn HEADs#2589

Merged
Sebastian Thiel (Byron) merged 3 commits into
mainfrom
fix-status-in-unborn-repo
May 8, 2026
Merged

Let is_dirty handle unborn HEADs#2589
Sebastian Thiel (Byron) merged 3 commits into
mainfrom
fix-status-in-unborn-repo

Conversation

@Byron

@Byron Sebastian Thiel (Byron) commented May 8, 2026

Copy link
Copy Markdown
Member

Tasks

  • refackiew

Summary

  • make Repository::is_dirty() use the existing empty-tree fallback when HEAD is unborn
  • add a regression test for a freshly initialized repository with no commits and an untracked file
  • preserve the documented behavior that untracked files do not make is_dirty() dirty

Refs #2587

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 this patch follows gix's existing head_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_error
  • cargo test -p gix --test gix status::is_dirty
  • cargo test -p gix --test gix status
  • cargo fmt --all
  • codex review --uncommitted
  • codex review --commit 5b0fda373dcf8df44750b65ab3343c8cf9d23189

Disclosure

This draft PR was created by Codex on behalf of Byron. Byron will review it before it is marked ready.

Codex (codex) and others added 2 commits May 8, 2026 10:45
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>
@Byron Sebastian Thiel (Byron) force-pushed the fix-status-in-unborn-repo branch from 5b0fda3 to 3406b1d Compare May 8, 2026 02:50
@Byron Sebastian Thiel (Byron) marked this pull request as ready for review May 8, 2026 02:50
Copilot AI review requested due to automatic review settings May 8, 2026 02:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() in Repository::is_dirty() to avoid errors on unborn HEAD.
  • Add fixtures and tests for unborn-HEAD scenarios (untracked-only and index-added files).
  • Extend the status fixture generator script with a new added-unborn repository.

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.

Comment thread gix/tests/fixtures/make_status_repos.sh
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>
@Byron Sebastian Thiel (Byron) merged commit ba7d9a4 into main May 8, 2026
32 checks passed
@Byron Sebastian Thiel (Byron) deleted the fix-status-in-unborn-repo branch May 8, 2026 04:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants