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
f3f2c6d811Cole Miller committed on 4/16/2025, 3:32:59 AM· committed by GitHubparent41cffa6
3 files changedLine totals unavailable