beads: move worktree/workspace validation to server-side

This commit is contained in:
Levi Neely 2026-03-16 15:04:13 +01:00
parent 42ccb8f096
commit ff58ef9438
2 changed files with 15 additions and 12 deletions

View File

@ -186,6 +186,21 @@ func (b *BeadsFS) Mount(name, cwd string) error {
return fmt.Errorf("mount path must be exactly 1 level deep from project dirs (%v)", config.ProjectDirs)
}
}
// Reject if cwd is a git worktree (not the main repo)
gitPath := filepath.Join(cwd, ".git")
if info, err := os.Stat(gitPath); err == nil && !info.IsDir() {
return fmt.Errorf("mount path is a git worktree, not a base repo — mount the parent project instead")
}
// Reject if cwd contains git worktrees (feature workspace, not base workspace)
entries, _ := os.ReadDir(cwd)
for _, e := range entries {
if e.IsDir() {
subGit := filepath.Join(cwd, e.Name(), ".git")
if info, err := os.Stat(subGit); err == nil && !info.IsDir() {
return fmt.Errorf("mount path contains git worktrees — this is a feature workspace, mount the base workspace instead")
}
}
}
// Warn if new mount overlaps with existing mounts
for _, m := range b.mounts {
if strings.HasPrefix(cwd, m.cwd+"/") {

View File

@ -20,18 +20,6 @@ if [ -z "$CWD" ]; then
exit 1
fi
# Reject if CWD is a git worktree (not the main repo)
if [ -f "$CWD/.git" ]; then
echo "error: $CWD is a git worktree, not a base repo — mount the parent project instead" >&2
exit 1
fi
# Reject if CWD contains git worktrees (feature workspace, not base workspace)
if find "$CWD" -maxdepth 2 -name ".git" -type f 2>/dev/null | grep -q .; then
echo "error: $CWD contains git worktrees — this is a feature workspace, mount the base workspace instead" >&2
exit 1
fi
MOUNT=$(uuidgen | cut -d- -f1)
echo "mount $CWD $MOUNT" | 9p write anvillm/beads/ctl