# Fix commondir discovery for git submodules \(\#28802\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/f3f2c6d8114ac9273b6eab6867837a370e59cbdf)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: f3f2c6d8114ac9273b6eab6867837a370e59cbdf

Requested commit: f3f2c6d8114ac9273b6eab6867837a370e59cbdf

Commit: f3f2c6d8114ac9273b6eab6867837a370e59cbdf

Tree: 73212df116c6e202de7ea55d45ece7b745bace8b

Author: Cole Miller

Committer: GitHub

## Message

```
Fix commondir discovery for git submodules (#28802)

The implementation of commondir discovery in #27885 was wrong, most
significantly for submodules but also for worktrees in rarer cases. The
correct procedure, implemented in this PR, is:

> If `.git` is a file, look at the `gitdir` it points to. If that
directory has a file called `commondir`, read that file to find the
commondir. (This is what happens for worktrees.) Otherwise, the
commondir is the same as the gitdir. (This is what happens for
submodules.)

Release Notes:

- N/A
```

## Parents

- [41cffa64b07a0093fe6b741c19832ef0f7f61f2f](https://git.cafe/gitcafe/zed/commit/41cffa64b07a0093fe6b741c19832ef0f7f61f2f?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/f3f2c6d8114ac9273b6eab6867837a370e59cbdf?format=markdown)
