Repository navigation
Report AlreadyExisted for a submodule, worktree or separate-git-dir target [patch] - #182
Merged
Merged
Conversation
…arget [patch] Init's probe treated any absolute --git-dir answer as "a repository above the target", but git prints one too when the target's .git is a file pointing elsewhere. git re-initializes those repositories and ignores --initial-branch, while AlreadyExisted said a fresh one was created. Ask rev-parse for --is-bare-repository and --show-cdup as well, and treat an empty cdup (the working-tree root) as the repository being at the target. Fixes #138 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01W83XxSnDX5Fu4sVPDKjXem
Path.Combine drops earlier arguments when a later one is rooted; Path.Join never does. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01W83XxSnDX5Fu4sVPDKjXem
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #138
What changed
GitInitBuilder.ProbeAsyncdecided that a repository already existed only whenrev-parse --git-dirprinted.gitor.. It treated an absolute path as meaning "the repository is in an ancestor directory". git also prints an absolute path for a repository rooted at the target whose.gitis a file: a submodule, a linked worktree, or a--separate-git-dirrepository. git re-initializes those repositories and ignores--initial-branch, butAlreadyExistedcame backfalse.The probe now runs
rev-parse --is-bare-repository --git-dir --show-cdup, and the newIsRepositoryRootreads its output:--git-diris.: the target is a git directory itself (a bare repository or a.gitdirectory). The answer is yes, as before.--show-cdupis empty, meaning the target is the root of the working tree. A subdirectory prints../and so on.This approach compares no paths, so symlinked temp directories and case differences on Windows/macOS can't cause a mismatch. A note in CLAUDE.md now describes the new probe.
Tests
.gitfile at the target, and a table test runsIsRepositoryRootagainst every layout.AlreadyExistedistruefor a--separate-git-dirrepository and for agit worktree addworktree, and stillfalsefor a plain subdirectory of a repository.Results with git 2.43:
.git/.rule restored, the 4 new positive tests fail. With the fix, they pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01W83XxSnDX5Fu4sVPDKjXem
Generated by Claude Code