Skip to content

fix(index): find the git dir from any directory in the repository - #82

Merged
yanxue06 merged 1 commit into
mainfrom
fix/resolve-git-dir-from-any-subdirectory
Aug 12, 2026
Merged

fix(index): find the git dir from any directory in the repository#82
yanxue06 merged 1 commit into
mainfrom
fix/resolve-git-dir-from-any-subdirectory

Conversation

@yanxue06

Copy link
Copy Markdown
Owner

git-semantic only worked from the repository root. One directory down it claimed you were not in a git repository:

$ cd src && git-semantic search "race condition"

  error: not a git repository: .git directory not found
  hint: Make sure you're inside a git repository, or use --path to specify one.
  code: E3001

RepositoryParser already discovers the repository the way git does, walking up from wherever it was invoked. IndexStorage did not — it looked for ./.git and gave up. The two halves of the tool disagreed about which directory counts as "the repository".

Both now discover. Three things follow:

  • Subdirectories work. index, search, update, and stats resolve to the same index no matter where in the tree they run.
  • Submodules land in the right place. A submodule's .git file points at the parent with a relative path (gitdir: ../.git/modules/<name>). Reading that file by hand resolved it against the process's working directory, putting the index outside the repository.
  • A broken worktree keeps its own error. InvalidGitFile now marks a .git entry that exists but does not resolve, instead of being reported as "not a git repository".

Tests

Four new cases in src/index/storage.rs: root and subdirectory agree, a subdirectory reads back what the root wrote, a relative gitdir: pointer resolves against the repository, and a dangling pointer is not misreported.

The storage and ANN/hybrid suites built a bare .git directory that no git tool would accept. They now initialize real repositories, which is what their file headers claimed all along.

Verified by hand: stats from src/ behaves identically to stats from the root, and a genuine non-repository still errors.


First of four stacked PRs. Merge order: this → #shell-completions → #zero-config-first-run → #quiet-logs.

`RepositoryParser` discovers the repository the way git does, walking up
from wherever it was invoked. `IndexStorage` did not — it looked for
`./.git` and gave up. So every command worked from the repository root
and reported "not a git repository" one directory down, which is where
most people actually are:

    $ cd src && git-semantic search "race condition"
    error: not a git repository: .git directory not found

Discovery also resolves the `gitdir:` pointer in a linked worktree's or
submodule's `.git` file. Submodules write that pointer relative to the
submodule directory (`gitdir: ../.git/modules/<name>`); reading the file
by hand resolved it against the process's working directory instead and
put the index outside the repository.

`InvalidGitFile` now marks a `.git` entry that exists but does not
resolve, so a broken worktree keeps its own hint instead of being told it
is not in a repository.

The storage tests built a bare `.git` directory that no git tool would
accept. They now initialize real repositories, which is what the file
headers claimed all along.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@yanxue06 yanxue06 added bug Something isn't working release labels Aug 12, 2026
@yanxue06
yanxue06 merged commit dcf4b8d into main Aug 12, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant