{"record":{"id":"1bacbcb5add68d3d","repo":"gastownhall/beads","slug":"failed-to-pin-target-git-marker-identity-w","errorCode":null,"errorMessage":"failed to pin target git marker identity: %w","messagePattern":"failed to pin target git marker identity: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/worktree_cmd.go","lineNumber":1021,"sourceCode":"\t}\n\tpathInfo, err := os.Lstat(worktree.path)\n\tif err != nil {\n\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{","sourceCodeStart":1003,"sourceCodeEnd":1039,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/worktree_cmd.go#L1003-L1039","documentation":"bd pins the worktree's `.git` marker file (the plain-text file inside a linked worktree pointing at its gitdir) via `os.Lstat` before removal. This error means the marker could not be stat'ed at all — it is missing or unreadable — so bd cannot verify the target is a genuine, intact linked worktree.","triggerScenarios":"`bd worktree remove <name>` or observeRevalidation when `<worktree path>/.git` does not exist or cannot be lstat'ed (permission denied, deleted while bd ran, I/O error).","commonSituations":"Deleting the `.git` file inside a linked worktree; running removal after a partially-failed cleanup; read-only or inaccessible worktree directories; Windows/network mounts hiding the file.","solutions":["Verify `<worktree>/.git` exists and is readable: `ls -la <worktree>/.git`; recreate it (`echo \"gitdir: /repo/.git/worktrees/<name>\" > .git`) if deleted","Run `git worktree repair` from the main repository to restore links","If the worktree is unwanted, delete the directory manually and run `git worktree prune`"],"exampleFix":"// before: marker missing, removal fails\n// after: repair registration\ncd /repo && git worktree repair && bd worktree remove mywt","handlingStrategy":"validation","validationCode":"if _, err := os.Lstat(filepath.Join(worktreePath, \".git\")); err != nil {\n    return fmt.Errorf(\"refusing: worktree marker missing: %w\", err)\n}","typeGuard":"func hasGitMarker(worktreePath string) bool {\n    _, err := os.Lstat(filepath.Join(worktreePath, \".git\"))\n    return err == nil\n}","tryCatchPattern":null,"preventionTips":["Never delete the `.git` pointer file inside a linked worktree","Run `git worktree repair` after moving repositories","Verify worktree integrity with `git worktree list` before batch operations"],"tags":["git","worktree","filesystem"],"backgroundTag":"worktree-git-marker-missing","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}