Repository navigation
claude.sh: make git work from a git worktree - #4836
Conversation
A worktree's .git file points to the main checkout by absolute path. claude.sh mounts only the worktree, so git in the container failed with "not a git repository". claude.sh now also mounts the main .git directory at the same path. The paths of the other worktrees do not exist in the container. git gc there could then prune their records from the shared .git directory. claude.sh sets gc.worktreePruneExpire=never in the container to stop this. Signed-off-by: Vitor Bandeira <vvbandeira@precisioninno.com>
Submodule .git files in a worktree hold a relative path to the main .git directory. That path did not resolve from /workspace, so git failed for an initialized submodule. The worktree is now also mounted at its host path, and the shell starts there. The current worktree is then no longer stale for git in the container. Git before 2.31 prints the unknown --path-format option as output, so the mount was wrong on those hosts. Resolve --git-common-dir with cd and pwd -P instead. Host paths under /workspace or /home/claude-user would nest inside the container mounts. Skip the extra mounts there and print a warning. Signed-off-by: Vitor Bandeira <vvbandeira@precisioninno.com>
git rev-parse searches upward. A plain folder inside another repository, such as a home folder in git, got that repository's .git mounted read-write. Mount it only when the folder is the top of its checkout. The entrypoint sourced /workspace/env.sh, so OPENROAD, FLOW_HOME and PATH pointed to /workspace even when the shell started in the host path. Git links in submodules do not resolve from there. Source env.sh from the start directory when it has one. The old-git test now passes --path-format only when the caller does, and the worktree case runs through it too. The docs state the changed session and build paths. Signed-off-by: Vitor Bandeira <vvbandeira@precisioninno.com>
env.sh split its own path at spaces, because the inner command substitution was not quoted. The Claude container entrypoint now sources env.sh from the worktree's host path, which can contain spaces, so OPENROAD, FLOW_HOME and PATH came out wrong. The test now checks env.sh in a path with a space, and which env.sh the entrypoint sources. Signed-off-by: Vitor Bandeira <vvbandeira@precisioninno.com>
There was a problem hiding this comment.
Code Review
This pull request introduces support for running the container from a Git worktree by mounting both the worktree and the main checkout's Git directory at their host paths, and updates the entrypoint to source env.sh from the active directory. It also disables automatic worktree pruning inside the container and adds a comprehensive test script to verify these mounts. The review feedback correctly identifies a potential test failure when GPG signing is globally enabled on the host, suggesting to explicitly disable it during the test commit.
🔍 QoR checkMetrics reflect the PR merge build — i.e. what will land on the target branch. Commit 62 design(s) checked — 0 with regression(s), 0 without a comparable baseline. |
With commit.gpgsign=true in the user's git config, the fixture commit tried to sign with a key for the test identity and failed. Signed-off-by: Vitor Bandeira <vvbandeira@precisioninno.com>
claude.shmounts only its own folder as/workspace.When that folder is a git worktree, its
.gitfile points to the main checkout's.gitdirectory by host path, and that path is not in the container.Every git command in the container then fails with
fatal: not a git repository, so Claude cannot diff, commit, or check status.When
claude.shruns from the top of a worktree, it now also mounts the worktree and the main.gitdirectory at their host paths, and starts the shell in the worktree's host path.The entrypoint sources
env.shfrom that start directory, soOPENROAD,FLOW_HOMEandPATHuse the same paths, and relative git links of submodules such astools/OpenROADresolve.A main checkout, or a plain folder inside another repository, gets no extra mount.
The paths of the other worktrees do not exist in the container, so
git gcthere would prune their records from the shared.gitdirectory.claude.shsetsgc.worktreePruneExpire=neverin the container to stop this.The docs warn against
git worktree pruneandrepairin the container, and state that hooks and config in the mounted.gitrun on the host.env.shnow quotes its own path, because the host path can contain spaces.Test
bash docker/test-claude-sh.shchecks thedocker runarguments with a stubdocker, and theenv.shthat the entrypoint sources.It needs no container engine.
In a container with rootless podman, started by
claude.shfrom a worktree with an initialized submodule:git statusfailed withfatal: not a git repository.git gckept the record of an older worktree.Host paths under
/workspaceor/home/claude-userwould nest inside the container mounts, soclaude.shprints a warning there and adds no mounts.Rebuild the image with
./claude.sh --buildto get the new entrypoint.This PR and #4791 both change the entrypoint list in
docs/user/ClaudeCode.md.The second one to merge needs a one-line merge fix there.