Skip to content

Match git check-ignore for tracked ignored paths#2564

Open
Sebastian Thiel (Byron) wants to merge 1 commit into
mainfrom
fix/check-ignore-index-2562
Open

Match git check-ignore for tracked ignored paths#2564
Sebastian Thiel (Byron) wants to merge 1 commit into
mainfrom
fix/check-ignore-index-2562

Conversation

@Byron
Copy link
Copy Markdown
Member

@Byron Sebastian Thiel (Byron) commented Apr 30, 2026

Codex created this PR on behalf of Byron. Byron will review it.

Fixes #2562

Summary

  • suppress gix exclude query ignore matches for paths that are present in the index, matching git check-ignore
  • preserve pathspec expansion behavior for tracked entries, exclusions, top magic, and attribute-qualified pathspecs
  • add the tracked-under-ignored-directory case to the gix-worktree ignore baseline fixture, with baseline input/output files written in the fixture execution directory

Git baseline

For a repository with .gitignore containing bin/ and force-added src/bin/stub_gen.rs, git check-ignore -vn --stdin reports no ignore pattern for:

  • src/bin
  • src/bin/
  • src/bin/stub_gen.rs

It still reports .gitignore:1:bin/ for untracked ignored paths:

  • src/bin/extra.txt
  • other/bin
  • other/bin/file.txt

gix status --ignored matching --no-write already matched Git for this repro, so the fix is scoped to gix exclude query rather than dirwalk.

Validation

  • cargo test -p gitoxide-core --lib --quiet
  • GIX_TEST_IGNORE_ARCHIVES=1 cargo test -p gix-worktree-tests worktree::stack::ignore --quiet

Copilot AI review requested due to automatic review settings April 30, 2026 23:25
Fix gix exclude query so ignore matches are suppressed for paths that are present in the index, matching git check-ignore behavior for tracked files under ignored directories.

The issue reproduces with a root ignore rule like bin/ and a force-added tracked file such as src/bin/stub_gen.rs. Git reports no ignore pattern for src/bin, src/bin/, or src/bin/stub_gen.rs, but still reports the bin/ rule for untracked paths like src/bin/extra.txt and other/bin/file.txt. gix status already matched this behavior through the dirwalk, so the fix is in the exclude query command path.

The query implementation now checks the index before printing exclude matches, preserves stdin paths relative to the caller current directory, and keeps pathspec expansion semantics for tracked entries, exclusions, top magic, and attribute-qualified pathspecs.

Tests cover both gix exclude query input modes against git check-ignore -vn --stdin, subdirectory stdin handling, pathspec expansion behavior, and the gix-worktree ignore baseline case for tracked files under ignored directories.

Validation:
- cargo test -p gitoxide-core --lib --quiet
- GIX_TEST_IGNORE_ARCHIVES=1 cargo test -p gix-worktree-tests worktree::stack::ignore --quiet

Fixes #2562
@Byron Sebastian Thiel (Byron) force-pushed the fix/check-ignore-index-2562 branch from a9232e6 to 66f8bc3 Compare April 30, 2026 23:31
Copy link
Copy Markdown

Copilot AI left a comment

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 updates ignore/exclude querying to match git check-ignore semantics for paths that are ignored but tracked (or contain tracked entries), and extends the fixture baseline to cover the “tracked under ignored directory” scenario described in #2562.

Changes:

  • Update the gitoxide-core exclude query implementation to suppress ignore matches for tracked paths (and tracked directories) based on index presence, aligning output with git check-ignore.
  • Extend the gix-worktree ignore baseline fixture to include ignored directories containing tracked files, and adjust the test harness to read baseline inputs/outputs from the fixture execution directory.
  • Add targeted unit tests in gitoxide-core to lock in expected behavior (tracked paths suppression, stdin path relativity, and pathspec expansion preservation).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
gix-worktree/tests/worktree/stack/ignore.rs Adjusts baseline test logic to suppress ignore matches when the index indicates the path is tracked (or a tracked directory).
gix-worktree/tests/fixtures/make_ignore_and_attributes_setup.sh Updates fixture repo setup and baseline generation to include the tracked-under-ignored-directory case and to emit baseline files in the fixture execution dir.
gitoxide-core/src/repository/exclude.rs Implements index-based suppression of ignore matches and adds tests to verify parity with git check-ignore and preserve pathspec-related behavior.

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.

Clarify handling of ignored directories that contain tracked files

3 participants