{"record":{"id":"1b869c69f632dc3f","repo":"gastownhall/beads","slug":"git-returned-invalid-commit-object-id-q","errorCode":null,"errorMessage":"git returned invalid commit object ID %q","messagePattern":"git returned invalid commit object ID %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/worktree_cmd.go","lineNumber":1955,"sourceCode":"\toutput, err := git.output(\n\t\tctx,\n\t\texecutionRoot,\n\t\t\"rev-parse\",\n\t\t\"--verify\",\n\t\t\"--quiet\",\n\t\t\"--end-of-options\",\n\t\trefOrOID+\"^{commit}\",\n\t)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\toid := strings.TrimSpace(string(output))\n\thashLength, err := repositoryObjectIDLength(ctx, git, executionRoot)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tif !isHexObjectID(oid, hashLength) {\n\t\treturn \"\", fmt.Errorf(\"git returned invalid commit object ID %q\", oid)\n\t}\n\treturn strings.ToLower(oid), nil\n}\n\nfunc resolveUpstreamWorktreeComparator(\n\tctx context.Context,\n\tgit *worktreeRemovalGit,\n\texecutionRoot string,\n\ttarget pinnedWorktreeTarget,\n) (pinnedWorktreeComparator, error) {\n\tif target.branch == \"\" || target.detached {\n\t\treturn pinnedWorktreeComparator{}, fmt.Errorf(\n\t\t\t\"cannot verify unpushed commits: target is detached; use --merged-into <ref>\",\n\t\t)\n\t}\n\toutput, err := git.output(\n\t\tctx,\n\t\texecutionRoot,","sourceCodeStart":1937,"sourceCodeEnd":1973,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/worktree_cmd.go#L1937-L1973","documentation":"After `git rev-parse --verify --quiet <ref>^{commit}` succeeds, bd validates that the returned object ID is a hex string of the repository's expected hash length (SHA-1 = 40, SHA-256 = 64) before using it as a comparator. This error means git reported success but returned a value that is not a valid commit OID, indicating an unexpected git behavior or output parsing problem.","triggerScenarios":"`resolveWorktreeCommitOID` receives non-hex, wrong-length, or empty output from `git rev-parse` despite a zero exit code — e.g. a git build with unusual extensions output, locale-mangled output, or a hash-length mismatch between the repo's object format and what bd detected.","commonSituations":"Repositories configured for SHA-256 object format where the detected hash length disagrees; wrappers or aliases altering git output; corrupted ref files containing garbage that rev-parse echoes back; extremely old or patched git versions.","solutions":["Check the repo's object format: `git rev-parse --show-object-format` and ensure it matches expectations (sha1 or sha256)","Run `git rev-parse --verify <ref>^{commit}` manually and inspect the raw output","Verify git integrity/version: `git --version`; upgrade if it is an unusual or patched build","Run `git fsck` to detect corrupted refs producing garbage OIDs"],"exampleFix":"// before: repo in sha256 mode with mismatched tooling\n$ git rev-parse --show-object-format\nsha256\n// after: ensure consistent object format (reinit/convert repo or update bd)\n$ git init --object-format=sha1  # for new repos, or use a bd version supporting sha256","handlingStrategy":"validation","validationCode":"// confirm the ref resolves to a hex OID of the expected length before calling bd\nout, err := exec.Command(\"git\", \"rev-parse\", \"--verify\", ref+\"^{commit}\").Output()\nif err != nil {\n\treturn fmt.Errorf(\"ref %q does not resolve to a commit\", ref)\n}\noid := strings.TrimSpace(string(out))\nif len(oid) != 40 && len(oid) != 64 {\n\treturn fmt.Errorf(\"unexpected OID length %d for %q\", len(oid), ref)\n}\nif _, err := hex.DecodeString(oid); err != nil {\n\treturn fmt.Errorf(\"non-hex OID %q\", oid)\n}","typeGuard":"func isHexObjectID(s string, length int) bool {\n\tif len(s) != length { return false }\n\t_, err := hex.DecodeString(s)\n\treturn err == nil\n}","tryCatchPattern":"_, err := bd.WorktreeRemove(name)\nif err != nil && strings.Contains(err.Error(), \"invalid commit object ID\") {\n\t// check object format and git version, then retry or abort\n\treturn diagnoseObjectFormat(name)\n}","preventionTips":["Match the repository object format (sha1 vs sha256) across all tooling, including bd","Do not wrap git with scripts that alter stdout; use `git --no-pager` and clean environments","Run `git fsck` if refs may be corrupted","Keep git updated to a mainstream release"],"tags":["git","rev-parse","object-id","validation","worktree"],"backgroundTag":"git-invalid-object-id","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}