Skip to content

Read the .git file of a working tree like git - #261

Merged
lyrixx merged 1 commit into
mainfrom
git-file
Oct 14, 2026
Merged

lyrixx merged 1 commit into
mainfrom
git-file

Conversation

@lyrixx

@lyrixx lyrixx commented Oct 14, 2026

Copy link
Copy Markdown
Member

Supersedes #201, and fixes #200.

#201 proposed in 2023 to open a working tree whose .git is a file pointing to its git directory. 2.0 does it since #253, for linked worktrees, submodules and clones with --separate-git-dir, but only linked worktrees had a test, and some issues of the review of #201 were still there. RepositoryPaths now reads the file like git:

  • the \r of a file written on Windows stayed in the path, which then didn't exist;
  • gitdir: was accepted on any line, where git requires it first;
  • a NUL byte in the path made realpath() throw a ValueError, which isn't an exception of gitlib;
  • a file that can't be read, without permission for instance, was reported as one that doesn't point to a git directory.

Tests

  • A submodule, whose .git file holds a relative path, the case of No support for git submodules #200, and a clone with --separate-git-dir, whose .git file holds an absolute path, the case of Separate git directory support #201: they open with both drivers.
  • The line endings, the invalid files and an unreadable file.
  • Checked locally: both drivers pass the 626 tests, also with git 1.8.4, 2.17.1 and 2.25.1, and PHPStan and php-cs-fixer report nothing.

The commit credits @chris114782, whose PR started it. Thanks!

Since 2.0, a working tree whose .git is a file pointing to its git
directory opens: a linked worktree, a submodule, or a clone with
--separate-git-dir. Only linked worktrees had a test, and the file was
read unlike git:

- the "\r" of a file written on Windows stayed in the path, which then
  didn't exist;
- "gitdir: " was accepted on any line, where git requires it first;
- a NUL byte in the path made realpath() throw a ValueError, which isn't
  an exception of gitlib;
- a file that can't be read, without permission for instance, was
  reported as one that doesn't point to a git directory.

Both drivers read the file like git. A submodule, whose .git file holds
a relative path, and a clone with --separate-git-dir, whose one holds an
absolute path, have tests.

Fixes #200.

Co-authored-by: Chris Stretton <chriss@datainterconnect.co.uk>
@lyrixx
lyrixx merged commit ff02401 into main Oct 14, 2026
13 checks passed
@lyrixx
lyrixx deleted the git-file branch October 14, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

No support for git submodules

1 participant