{"record":{"id":"6b72e241c0a750a9","repo":"gastownhall/beads","slug":"target-common-git-directory-does-not-match-reposit","errorCode":null,"errorMessage":"target common git directory does not match repository","messagePattern":"target common git directory does not match repository","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/worktreeremove/policy.go","lineNumber":189,"sourceCode":"\tif request.Mode != Normal && request.Mode != Force {\n\t\treturn Plan{}, fmt.Errorf(\"worktree removal mode is absent or invalid\")\n\t}\n\tswitch facts.Target {\n\tcase PrimaryWorktree:\n\t\treturn Plan{}, fmt.Errorf(\"cannot remove the primary worktree\")\n\tcase CurrentWorktree:\n\t\treturn Plan{}, fmt.Errorf(\"cannot remove the worktree containing the running command\")\n\tcase RegisteredTarget:\n\tdefault:\n\t\treturn Plan{}, fmt.Errorf(\"registered worktree target is absent or invalid\")\n\t}\n\tif facts.Registration != Present || facts.RegisteredPath == \"\" ||\n\t\tfacts.TargetDir != Present || facts.GitAdminDir != Present ||\n\t\tfacts.GitMarker != Present || facts.Head != Present {\n\t\treturn Plan{}, fmt.Errorf(\"registered worktree target is absent or invalid\")\n\t}\n\tif facts.CommonDir != Matched {\n\t\treturn Plan{}, fmt.Errorf(\"target common git directory does not match repository\")\n\t}\n\tif facts.Status != Clean && facts.Status != Dirty {\n\t\treturn Plan{}, fmt.Errorf(\"worktree cleanliness observation is absent or invalid\")\n\t}\n\tif facts.ManagedIgnore != IgnoreAbsent && facts.ManagedIgnore != IgnoreManaged {\n\t\treturn Plan{}, fmt.Errorf(\"managed ignore observation is absent or invalid\")\n\t}\n\tif (facts.ManagedIgnore == IgnoreManaged) != (facts.ManagedIgnoreEntry != \"\") {\n\t\treturn Plan{}, fmt.Errorf(\"managed ignore cleanup identity is absent or invalid\")\n\t}\n\tif request.Mode != Force {\n\t\tif facts.Status != Clean {\n\t\t\treturn Plan{}, fmt.Errorf(\"worktree contains modified, untracked, or ignored files\")\n\t\t}\n\t\tif facts.Comparator != ComparatorAvailable && facts.Comparator != ComparatorMissing && facts.Comparator != ComparatorNotRequired {\n\t\t\treturn Plan{}, fmt.Errorf(\"worktree comparison target observation is absent or invalid\")\n\t\t}\n\t\tif facts.Comparator != ComparatorAvailable {","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/worktreeremove/policy.go#L171-L207","documentation":"Prepare rejects the request because facts.CommonDir is not Matched. The target worktree's common git directory does not resolve to the same repository git directory, meaning the registered worktree belongs to (or was relinked to) a different repository. The library refuses removal to avoid deleting a worktree owned by another repo.","triggerScenarios":"Calling Prepare with PrepareFacts.CommonDir set to anything other than Matched (e.g. Mismatched or Unknown), typically produced when the worktree's .git file commondir path does not match the repository's admin dir.","commonSituations":"A worktree copied or moved between clones; a manually edited .git/worktrees/<name>/commondir; testing with fabricated facts that never assert CommonDir: Matched.","solutions":["Set facts.CommonDir to Matched only after verifying the worktree's commondir resolves to the same repository","Repair or re-register the worktree with git worktree repair so commondir matches","If testing, include CommonDir: worktreeremove.Matched in the PrepareFacts"],"exampleFix":"// before\nfacts.CommonDir = worktreeremove.Unknown\n// after\nfacts.CommonDir = worktreeremove.Matched // verify commondir matches repo first","handlingStrategy":"validation","validationCode":"if facts.CommonDir != worktreeremove.Matched {\n\treturn fmt.Errorf(\"worktree %s does not belong to this repository\", facts.RegisteredPath)\n}","typeGuard":"func commonDirMatched(f worktreeremove.PrepareFacts) bool {\n\treturn f.CommonDir == worktreeremove.Matched\n}","tryCatchPattern":"plan, err := worktreeremove.Prepare(req, facts)\nif err != nil && strings.Contains(err.Error(), \"common git directory does not match\") {\n\treturn fmt.Errorf(\"run git worktree repair or re-register the worktree: %w\", err)\n}","preventionTips":["Verify commondir resolution before preparing removal","Never hand-edit .git/worktrees/<name>/commondir","Re-register moved/copied worktrees instead of relinking manually"],"tags":["worktree","git","validation"],"backgroundTag":"worktree-commondir-mismatch","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}