{"record":{"id":"1aa8a6b8cfe26b51","repo":"alibaba/open-code-review","slug":"s-value-q-is-not-a-valid-commit-ref","errorCode":null,"errorMessage":"%s value %q is not a valid commit ref","messagePattern":"(.+?) value %q is not a valid commit ref","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/review_cmd.go","lineNumber":482,"sourceCode":"\t\tref  string\n\t}{\n\t\t{\"--from\", opts.from},\n\t\t{\"--to\", opts.to},\n\t\t{\"--commit\", opts.commit},\n\t}\n\tfor _, item := range refs {\n\t\tif item.ref == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tif strings.HasPrefix(item.ref, \"-\") {\n\t\t\treturn fmt.Errorf(\"%s value %q is not a valid git ref: refs must not start with '-'\", item.flag, item.ref)\n\t\t}\n\t\tif out, err := runGitCmd(repoDir, \"rev-parse\", \"--verify\", \"--end-of-options\", item.ref+\"^{commit}\"); err != nil {\n\t\t\tmsg := strings.TrimSpace(string(out))\n\t\t\tif msg != \"\" {\n\t\t\t\treturn fmt.Errorf(\"%s value %q is not a valid commit ref: %s\", item.flag, item.ref, msg)\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"%s value %q is not a valid commit ref\", item.flag, item.ref)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc runPreviewContext(ctx context.Context, cc *commonContext, opts reviewOptions, out io.Writer) error {\n\tpreview, err := agent.Preview(ctx, agent.Args{\n\t\tRepoDir:    cc.RepoDir,\n\t\tFrom:       opts.from,\n\t\tTo:         opts.to,\n\t\tCommit:     opts.commit,\n\t\tFileFilter: cc.FileFilter,\n\t\tGitRunner:  cc.GitRunner,\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"preview failed: %w\", err)\n\t}\n","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/review_cmd.go#L464-L500","documentation":"Same check as the message-bearing variant: when `git rev-parse --verify --end-of-options <ref>^{commit}` fails but git produced no output, validateReviewRefs returns this shorter error. It indicates an unresolvable ref with no diagnostic from git (e.g. command-level failure, empty output).","triggerScenarios":"--from/--to/--commit value that fails rev-parse with empty stderr/stdout — unusual git failures, corrupted refs, or a git runner that swallows output.","commonSituations":"Corrupted or pruned .git/refs; custom GitRunner in tests not returning output; exotic ref expressions git silently rejects.","solutions":["Run `git rev-parse --verify <value>^{commit}` manually to see git's own diagnosis.","Replace the ref with a plain commit SHA, which avoids ref-expression parsing entirely.","Inspect the repo's refs (`git show-ref`) for corruption and run `git fsck` if suspect."],"exampleFix":"// before\nocr review --commit HEAD^3^{tree}\n// after\nocr review --commit $(git rev-parse HEAD~3)","handlingStrategy":"validation","validationCode":"out, err := exec.Command(\"git\", \"rev-parse\", \"--verify\", ref+\"^{commit}\").CombinedOutput()\nif err != nil || len(bytes.TrimSpace(out)) == 0 {\n    return fmt.Errorf(\"ref %q unusable, use a full commit SHA instead\", ref)\n}","typeGuard":null,"tryCatchPattern":"if err := validateReviewRefs(repoDir, opts); err != nil {\n    // no git message available: fall back to a plain SHA\n    return fmt.Errorf(\"use `git rev-parse <ref>` to obtain a SHA and retry: %w\", err)\n}","preventionTips":["Use full commit SHAs in automation instead of ref expressions.","Run `git fsck` if refs silently fail to resolve.","Keep .git/refs intact; avoid hand-editing ref files."],"tags":["git","ref-validation"],"backgroundTag":"invalid-git-ref","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}