Skip to content

Support git worktrees in lamdera check git-repo detection#99

Draft
elliotfiske wants to merge 1 commit into
lamdera:lamdera-nextfrom
elliotfiske:worktree-git-support
Draft

Support git worktrees in lamdera check git-repo detection#99
elliotfiske wants to merge 1 commit into
lamdera:lamdera-nextfrom
elliotfiske:worktree-git-support

Conversation

@elliotfiske
Copy link
Copy Markdown

Problem

Running lamdera check (or lamdera init) from inside a git worktree fails with:

It looks like your project is missing a git repository!

In a normal clone, .git is a directory. In a worktree it's instead a text file containing a gitdir: <path> pointer to the real git directory under the main checkout's .git/worktrees/<name>. The compiler only checked for a .git directory (Dir.doesDirectoryExist), so it concluded there was no repo — and offered to run git init, which would clobber the worktree's .git file.

Every other git operation in the compiler shells out to the git binary (which resolves the .git file natively), so this directory check was the only blocker.

Change

  • Add gitRepoStatus to the Lamdera prelude. It recognises:
    • a .git directory → normal repo,
    • a .git file → follows the gitdir: pointer and verifies the target directory exists (worktree),
    • absent → uninitialised (safe to git init),
    • a .git file that's malformed or points nowhere → a broken state with a specific reason.
  • checkGitInitialised now treats a worktree as a valid repo; only a genuinely missing repo triggers the git init prompt, and a broken worktree raises a clear BROKEN GIT WORKTREE error (rather than silently offering git init).
  • Init.writeDefaultImplementations gates its git init on the missing state too.

Tests

Added test/Test/Check.hs scopes covering: no .git, a normal .git dir, a real worktree created via git worktree add, a malformed .git file, and a dangling gitdir: 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 Test workflow) to validate the build + tests across the matrix. Feedback very welcome on style/idiom.

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants