{"record":{"id":"5c5983f2959a708d","repo":"gastownhall/beads","slug":"failed-to-resolve-repository-common-git-directory","errorCode":null,"errorMessage":"failed to resolve repository common git directory: %w","messagePattern":"failed to resolve repository common git directory: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/worktree_cmd.go","lineNumber":1270,"sourceCode":"\tif sameWorktreePath(targetEntry.path, currentRoot) {\n\t\tplan.prepareFacts.Target = worktreeremove.CurrentWorktree\n\t\treturn plan, nil\n\t}\n\tif afterTargetResolution != nil {\n\t\tif err := afterTargetResolution(); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"worktree removal interrupted after target resolution: %w\", err)\n\t\t}\n\t}\n\n\tmainCommonDirOutput, err := gitRunner.output(\n\t\tctx,\n\t\tmainWorktree.path,\n\t\t\"rev-parse\",\n\t\t\"--path-format=absolute\",\n\t\t\"--git-common-dir\",\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to resolve repository common git directory: %w\", err)\n\t}\n\tmainCommonDir := filepath.Clean(strings.TrimSpace(string(mainCommonDirOutput)))\n\n\ttarget, err := inspectWorktreeTarget(ctx, gitRunner, targetEntry)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tplan = &worktreeRemovalPlan{\n\t\tgit:           gitRunner,\n\t\texecutionRoot: filepath.Clean(mainWorktree.path),\n\t\tmainWorktree:  filepath.Clean(mainWorktree.path),\n\t\tcommonDir:     mainCommonDir,\n\t\ttarget:        target,\n\t\tforce:         options.force.value,\n\t}\n\tstatus := worktreeremove.Clean\n\tif target.status != \"\" {\n\t\tstatus = worktreeremove.Dirty","sourceCodeStart":1252,"sourceCodeEnd":1288,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/worktree_cmd.go#L1252-L1288","documentation":"bd failed to run `git rev-parse --path-format=absolute --git-common-dir` from the primary worktree, which is needed to learn the repository's shared/common git directory before planning the removal. Without the common dir, bd cannot verify that the target worktree belongs to the same repository. The underlying git error is wrapped via %w.","triggerScenarios":"Calling `bd worktree remove` when `git rev-parse --git-common-dir` fails in the primary worktree path: corrupted primary .git file/directory, unsupported git version lacking --path-format, or the primary worktree directory being unreadable.","commonSituations":"Very old git (< 2.31) that does not support --path-format=absolute; a deleted or corrupt .git in the main worktree; permission issues on the main worktree path; GIT_DIR overrides breaking resolution.","solutions":["Upgrade git to >= 2.31 which supports `--path-format=absolute`","Run `git rev-parse --path-format=absolute --git-common-dir` in the primary worktree manually and fix the reported git error (repair .git, permissions)","Remove any GIT_DIR/GIT_COMMON_DIR env overrides that confuse rev-parse","Restore or re-clone the repository if its .git structure is corrupt"],"exampleFix":"// before: git 2.25\n$ bd worktree remove feature-x\n// error: failed to resolve repository common git directory: unknown option: --path-format\n// after\n$ brew upgrade git  # or apt install newer git (>= 2.31)\n$ bd worktree remove feature-x","handlingStrategy":"validation","validationCode":"git rev-parse --path-format=absolute --git-common-dir >/dev/null 2>&1 || { echo 'git too old or repo broken'; exit 1; }","typeGuard":"func supportsPathFormat() bool {\n\treturn exec.Command(\"git\", \"rev-parse\", \"--path-format=absolute\", \"--git-common-dir\").Run() == nil\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"common git directory\") {\n\tif !isGitVersionAtLeast(2, 31) {\n\t\treturn fmt.Errorf(\"upgrade git to >= 2.31\")\n\t}\n\treturn err\n}","preventionTips":["Require git >= 2.31 in your environment/docs","Verify the primary worktree's .git is intact before worktree operations","Avoid GIT_DIR/GIT_COMMON_DIR env overrides in automation","Run `git fsck`/repair if the repo structure is suspect"],"tags":["git","worktree","version-compatibility"],"backgroundTag":"git-command-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}