Support git worktrees in lamdera check git-repo detection#99
Draft
elliotfiske wants to merge 1 commit into
Draft
Support git worktrees in lamdera check git-repo detection#99elliotfiske wants to merge 1 commit into
lamdera check git-repo detection#99elliotfiske wants to merge 1 commit into
Conversation
A git worktree's `.git` is a text file (`gitdir: <path>`) rather than a directory, so `Dir.doesDirectoryExist (root </> ".git")` returned False and `lamdera check` wrongly reported "missing a git repository" (and offered a `git init` that would clobber the worktree). Add `gitRepoStatus` to the Lamdera prelude: it recognises a `.git` directory, follows a worktree `.git` file's `gitdir:` pointer (verifying the target dir exists), and reports a specific reason for a malformed/dangling pointer. `checkGitInitialised` and `Init.writeDefaultImplementations` now use it; only a truly missing repo triggers `git init`, and a broken worktree raises a clear error instead. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
Running
lamdera check(orlamdera init) from inside a git worktree fails with:In a normal clone,
.gitis a directory. In a worktree it's instead a text file containing agitdir: <path>pointer to the real git directory under the main checkout's.git/worktrees/<name>. The compiler only checked for a.gitdirectory (Dir.doesDirectoryExist), so it concluded there was no repo — and offered to rungit init, which would clobber the worktree's.gitfile.Every other git operation in the compiler shells out to the
gitbinary (which resolves the.gitfile natively), so this directory check was the only blocker.Change
gitRepoStatusto theLamderaprelude. It recognises:.gitdirectory → normal repo,.gitfile → follows thegitdir:pointer and verifies the target directory exists (worktree),git init),.gitfile that's malformed or points nowhere → a broken state with a specific reason.checkGitInitialisednow treats a worktree as a valid repo; only a genuinely missing repo triggers thegit initprompt, and a broken worktree raises a clearBROKEN GIT WORKTREEerror (rather than silently offeringgit init).Init.writeDefaultImplementationsgates itsgit initon the missing state too.Tests
Added
test/Test/Check.hsscopes covering: no.git, a normal.gitdir, a real worktree created viagit worktree add, a malformed.gitfile, and a danglinggitdir:pointer.Notes
I don't develop in Haskell day-to-day and couldn't run the devbox/stack toolchain in my environment, so I'm leaning on this PR's CI (the
Testworkflow) to validate the build + tests across the matrix. Feedback very welcome on style/idiom.🤖 Generated with Claude Code