{"record":{"id":"38d4f0c7ec82cd6c","repo":"gastownhall/beads","slug":"target-git-marker-is-not-a-regular-file-s","errorCode":null,"errorMessage":"target git marker is not a regular file: %s","messagePattern":"target git marker is not a regular file: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/worktree_cmd.go","lineNumber":1024,"sourceCode":"\t\treturn pinnedWorktreeTarget{}, fmt.Errorf(\"failed to pin target directory identity: %w\", err)\n\t}\n\tif pathInfo.Mode()&os.ModeSymlink != 0 || !pathInfo.IsDir() {\n\t\treturn pinnedWorktreeTarget{}, fmt.Errorf(\"target path is not a real directory: %s\", worktree.path)\n\t}\n\tgitDirInfo, err := os.Lstat(gitDir)\n\tif err != nil {\n\t\treturn pinnedWorktreeTarget{}, fmt.Errorf(\"failed to pin target git directory identity: %w\", err)\n\t}\n\tif gitDirInfo.Mode()&os.ModeSymlink != 0 || !gitDirInfo.IsDir() {\n\t\treturn pinnedWorktreeTarget{}, fmt.Errorf(\"target git directory is not a real directory: %s\", gitDir)\n\t}\n\tgitMarkerPath := filepath.Join(worktree.path, \".git\")\n\tgitMarkerInfo, err := os.Lstat(gitMarkerPath)\n\tif err != nil {\n\t\treturn pinnedWorktreeTarget{}, fmt.Errorf(\"failed to pin target git marker identity: %w\", err)\n\t}\n\tif gitMarkerInfo.Mode()&os.ModeSymlink != 0 || !gitMarkerInfo.Mode().IsRegular() {\n\t\treturn pinnedWorktreeTarget{}, fmt.Errorf(\"target git marker is not a regular file: %s\", gitMarkerPath)\n\t}\n\tgitDirFingerprint, err := fingerprintWorktreeFilesystem(gitDir)\n\tif err != nil {\n\t\treturn pinnedWorktreeTarget{}, fmt.Errorf(\"failed to fingerprint target git directory: %w\", err)\n\t}\n\tgitMarkerFingerprint, err := fingerprintWorktreeFilesystem(gitMarkerPath)\n\tif err != nil {\n\t\treturn pinnedWorktreeTarget{}, fmt.Errorf(\"failed to fingerprint target git marker: %w\", err)\n\t}\n\tstatusFingerprint, err := fingerprintWorktreeStatusPaths(worktree.path, string(statusOutput))\n\tif err != nil {\n\t\treturn pinnedWorktreeTarget{}, fmt.Errorf(\"failed to fingerprint target changes: %w\", err)\n\t}\n\n\treturn pinnedWorktreeTarget{\n\t\tpath:                 filepath.Clean(worktree.path),\n\t\tpathInfo:             pathInfo,\n\t\tgitDir:               gitDir,","sourceCodeStart":1006,"sourceCodeEnd":1042,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/worktree_cmd.go#L1006-L1042","documentation":"A linked worktree must contain a regular `.git` file (a symlink or directory is rejected). bd rejects the removal target when `os.Lstat` shows the `.git` marker is a symlink or not a regular file, because fingerprinting and identity checks assume the standard git layout.","triggerScenarios":"`bd worktree remove <name>` or revalidation when `<worktree>/.git` is a symlink (common with submodules) or a directory (an embedded clone).","commonSituations":"Adding a submodule checkout or a plain nested clone and registering it as a 'worktree'; switching tooling that replaces .git with a symlink; manual restructuring of worktree directories.","solutions":["Confirm the target is really a linked git worktree (`git worktree list`) and not a nested clone or submodule","If it is a nested clone, remove it as a normal directory instead of via worktree removal","If it should be a worktree, recreate it with `git worktree add` so `.git` is a regular file"],"exampleFix":"// before: nested clone used as worktree\nmv mywt/ mywt.bak && git worktree add mywt -b mybranch\n// after: .git is a regular pointer file and removal succeeds","handlingStrategy":"validation","validationCode":"info, err := os.Lstat(filepath.Join(worktreePath, \".git\"))\nif err != nil || info.Mode()&os.ModeSymlink != 0 || !info.Mode().IsRegular() {\n    return fmt.Errorf(\"refusing: %s/.git is not a regular file\", worktreePath)\n}","typeGuard":"func isLinkedWorktree(path string) bool {\n    info, err := os.Lstat(filepath.Join(path, \".git\"))\n    return err == nil && info.Mode()&os.ModeSymlink == 0 && info.Mode().IsRegular()\n}","tryCatchPattern":null,"preventionTips":["Only register directories created by `git worktree add` as worktrees","Distinguish nested clones/submodules from linked worktrees before removal","Keep submodule checkouts out of `bd worktree` operations"],"tags":["git","worktree","validation"],"backgroundTag":"worktree-git-marker-invalid","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}