{"record":{"id":"b1acc5295559d7df","repo":"alibaba/open-code-review","slug":"git-log-failed-w","errorCode":null,"errorMessage":"git log failed: %w","messagePattern":"git log failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/git.go","lineNumber":30,"sourceCode":"func runGitCmd(repoDir string, args ...string) ([]byte, error) {\n\tfullArgs := append([]string{\"-C\", repoDir}, args...)\n\tcmd := exec.Command(\"git\", fullArgs...)\n\treturn cmd.CombinedOutput()\n}\n\n// runGitCmdStdout is like runGitCmd but returns stdout only. Use it when the\n// output is consumed as data (e.g. a resolved path) so git's stderr warnings\n// (permissions, deprecations, config notices) can't pollute the result.\nfunc runGitCmdStdout(repoDir string, args ...string) ([]byte, error) {\n\tfullArgs := append([]string{\"-C\", repoDir}, args...)\n\tcmd := exec.Command(\"git\", fullArgs...)\n\treturn cmd.Output()\n}\n\nfunc getCommitMessage(repoDir, commit string) (string, error) {\n\tout, err := runGitCmd(repoDir, \"log\", \"-1\", \"--format=%B\", \"--end-of-options\", commit)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"git log failed: %w\", err)\n\t}\n\treturn strings.TrimSpace(string(out)), nil\n}\n","sourceCodeStart":12,"sourceCodeEnd":34,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/git.go#L12-L34","documentation":"getCommitMessage runs `git log -1 --format=%B --end-of-options <commit>` via runGitCmd and wraps any git failure as \"git log failed: <cause>\". The %w wrap keeps the exit status/error from the underlying git process, so the caller can detect invalid or unknown commits.","triggerScenarios":"resolveBackground asked for the message of a commit that does not exist in the repo (e.g. a SHA from another repo, an abbreviated hash that matches nothing, or `HEAD` in an empty repo).","commonSituations":"Passing a full SHA from a fork after history was rewritten; shallow clone missing the commit; typo in a branch/commit name; running outside the repo (repoDir wrong).","solutions":["Check the wrapped cause — 'unknown revision' means the commit is absent from this repo","Run `git log -1 <commit>` manually in repoDir to reproduce","Fetch the missing commit (git fetch origin <sha>) or unshallow the clone","Verify repoDir points at the correct working repository"],"exampleFix":"// before\nmsg, err := getCommitMessage(repo, \"deadbeefdeadbeef\") // unknown revision\n// after\nif out, err := runGitCmd(repo, \"cat-file\", \"-t\", commit); err != nil || strings.TrimSpace(out) != \"commit\" {\n    return \"\", fmt.Errorf(\"commit %s not found in repository\", commit)\n}\nmsg, err := getCommitMessage(repo, commit)","handlingStrategy":"try-catch","validationCode":"func commitExists(dir, sha string) bool {\n    out, err := runGitCmd(dir, \"rev-parse\", \"--verify\", \"--quiet\", sha+\"^{commit}\")\n    return err == nil && out != \"\"\n}","typeGuard":null,"tryCatchPattern":"msg, err := getCommitMessage(repoDir, commit)\nif err != nil {\n    var ee *exec.ExitError\n    if errors.As(err, &ee) && strings.Contains(string(ee.Stderr), \"unknown revision\") {\n        return \"\", fmt.Errorf(\"commit %s not found: run 'git fetch' first\", commit)\n    }\n    return \"\", err\n}","preventionTips":["Verify the SHA exists with `git rev-parse --verify <sha>` before use","Fetch or unshallow before referencing commits from remotes","Pass full 40-char SHAs, not ambiguous abbreviations"],"tags":["git","cli","commit"],"backgroundTag":"git-revision-not-found","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}