Likeai e5be9608dd worktree: Only treat a directory as a bare repository when HEAD and config are files (#67024)
## Summary

`is_dot_git` decides whether a directory is a bare repository by
checking that a
`HEAD` and a `config` entry exist inside it. The check only tests for
existence,
so any directory that happens to contain entries with those names is
treated as
a bare repository.

A small Rust crate is enough to trigger this:

    exp/
    ├── Cargo.toml
    └── src/
        ├── main.rs
        └── exp/
            ├── mod.rs
            ├── head/
            │   └── mod.rs
            └── config/
                └── mod.rs

where `src/exp/mod.rs` simply declares the two modules:

    pub mod config;
    pub mod head;

On case-insensitive filesystems (macOS by default), `src/exp/HEAD`
resolves to
the `head` module directory, and `src/exp/config` exists, so `src/exp`
matches
the bare-repository heuristic. Zed then registers its parent, the
ordinary
source directory `src/`, as a Git repository. That repository has no
working
directory, so opening it fails in `Repository::check_access` with `bare
repositories do not have a working directory`. The Git panel maps any
access
failure to `GitAccess::No` and shows the "detected dubious ownership"
empty
state, where **Trust Directory** cannot help, since the real problem is
not
ownership.

Because the Git panel follows the repository of the active file, opening
`src/exp/config/mod.rs` silently switches away from the real repository
to the
bogus `src` entry. The stale entry survives restarts until the project
root is
reopened. This is unrelated to linked worktrees; the same layout
reproduces in a
plain checkout. On case-sensitive filesystems the directory must
literally be
named `HEAD` to match.

This change requires both entries to be files rather than merely
present, so
directories named `HEAD`/`head` or `config` no longer register as Git
metadata.
The `.git` fast path is untouched, and real bare repositories still
match because
their `HEAD` and `config` are files (symlinked `HEAD` included, as
`Fs::is_file`
resolves symlinks).

## Testing

Reproduced and manually verified on macOS with a case-insensitive
volume:

1. Create a crate named `exp` with modules `exp::head` and `exp::config`
   (`src/exp/head/mod.rs`, `src/exp/config/mod.rs`) and commit it.
2. Open the crate in Zed and then open `src/exp/config/mod.rs`.
3. Before: the repository selector lists two repositories, `exp` and a
bogus
`src`, and the Git panel for `src` shows the dubious-ownership empty
state.
Selecting `exp` restores Git, but opening the file again switches back
to
`src`. After: only `exp` is listed, and status, staging and committing
work
   for files under `src/exp/`.
4. Confirm no regression for real bare repositories by opening a bare
clone and
a linked worktree of it; both are still detected and their Git features
work.

No automated test was added for this case.

## Self-review

- [x] I've reviewed my diff for quality, security, reliability, and
performance.
- [x] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist).
- [x] Tests cover the new or changed behavior.

Release Notes:

- Fixed Git repository detection treating any directory containing
`HEAD` and
  `config` entries as a bare repository.
  

<img width="2040" height="1122" alt="截图Zed 1116101115"
src="https://github.com/user-attachments/assets/0629d47b-7cf1-41b2-95e3-0e9b631ca4ba"
/>

**After fixed**
  
<img width="1830" height="994" alt="截图zed 1116111127"
src="https://github.com/user-attachments/assets/fd1081c9-353e-48b0-b61a-eaf26ec6eb8e"
/>

---------

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2026-11-17 09:14:48 +00:00
…
…
2026-09-11 09:13:44 +00:00
…
…
…

Zed

Zed CI

Welcome to Zed, a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.


Installation

On macOS, Linux, and Windows you can download Zed directly or install Zed via your local package manager (macOS/Linux/Windows).

Other platforms are not yet available:

Developing Zed

Contributing

See CONTRIBUTING.md for ways you can contribute to Zed.

Also... we're hiring! Check out our jobs page for open roles.

Licensing

Zed source code is licensed primarily under GPL-3.0-or-later, with Apache-2.0 components where marked.

License information for third party dependencies must be correctly provided for CI to pass.

We use cargo-about to automatically comply with open source licenses. If CI is failing, check the following:

  • Is it showing a no license specified error for a crate you've created? If so, add publish = false under [package] in your crate's Cargo.toml.
  • Is the error failed to satisfy license requirements for a dependency? If so, first determine what license the project has and whether this system is sufficient to comply with this license's requirements. If you're unsure, ask a lawyer. Once you've verified that this system is acceptable add the license's SPDX identifier to the accepted array in script/licenses/zed-licenses.toml.
  • Is cargo-about unable to find the license for a dependency? If so, add a clarification field at the end of script/licenses/zed-licenses.toml, as specified in the cargo-about book.

Sponsorship

Zed is developed by Zed Industries, Inc., a for-profit company.

If you’d like to financially support the project, you can do so via GitHub Sponsors. Sponsorships go directly to Zed Industries and are used as general company revenue. There are no perks or entitlements associated with sponsorship.

S
Description
No description provided
Readme 1.6 GiB
Languages
Rust 95.4%
JSON-with-Comments 2.4%
Python 0.8%
Inno Setup 0.3%
Tree-sitter Query 0.3%
Other 0.4%