{"record":{"id":"4e77700e6f1ebe0f","repo":"tailscale/tailscale","slug":"getting-git-hash-w","errorCode":null,"errorMessage":"getting git hash: %w","messagePattern":"getting git hash: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"version/mkversion/mkversion.go","lineNumber":149,"sourceCode":"\n\tif modPath == \"\" {\n\t\treturn VersionInfo{}, fmt.Errorf(\"no module path in go.mod\")\n\t}\n\tif modPath == \"tailscale.com\" {\n\t\t// Invoked in the tailscale.com repo directly, just no further info to\n\t\t// collect.\n\t\tv, err := infoFromDir(gitRoot)\n\t\tif err != nil {\n\t\t\treturn VersionInfo{}, err\n\t\t}\n\t\treturn mkOutput(v)\n\t}\n\n\t// We seem to be in a repo that imports tailscale.com. Find the\n\t// tailscale.com repo and collect additional info from it.\n\totherHash, err := runner.output(\"git\", \"rev-parse\", \"HEAD\")\n\tif err != nil {\n\t\treturn VersionInfo{}, fmt.Errorf(\"getting git hash: %w\", err)\n\t}\n\totherDate, err := runner.output(\"git\", \"log\", \"-n1\", \"--format=%ct\", \"HEAD\")\n\tif err != nil {\n\t\treturn VersionInfo{}, fmt.Errorf(\"getting git date: %w\", err)\n\t}\n\n\t// Note, this mechanism doesn't correctly support go.mod replacements,\n\t// or go workdirs. We only parse out the commit ref from go.mod's\n\t// \"require\" line, nothing else.\n\ttailscaleRef, err := tailscaleModuleRef(modBs)\n\tif err != nil {\n\t\treturn VersionInfo{}, err\n\t}\n\n\tv, err := infoFromCache(tailscaleRef, runner)\n\tif err != nil {\n\t\treturn VersionInfo{}, err\n\t}","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/tailscale/tailscale/blob/6e0912f97994f927632b34ae9e63b53d6516a6ac/version/mkversion/mkversion.go#L131-L167","documentation":"You are in a repo whose module path is not tailscale.com, so mkversion treats it as a repo that imports tailscale.com and records its commit hash (OtherHash) via `git rev-parse HEAD`. This error means that command failed in your repo - classically because HEAD is unborn (the repo was `git init`ed but has zero commits) or points at a missing/corrupt ref.","triggerScenarios":"InfoFrom run in a freshly initialized repo with no commits ('fatal: your current branch 'main' does not have any commits yet'), a detached HEAD pointing to a pruned ref, or a corrupted object database.","commonSituations":"CI pipelines that build an experimental repo before its first commit; local scratch repos that import tailscale.com; aggressively pruned/gc'd clones.","solutions":["Create at least one commit (`git commit --allow-empty -m init`) so HEAD resolves","Reproduce manually with `git rev-parse HEAD` in the repo root to see git's exact complaint","If the ref is broken, check `git fsck` and reset HEAD to a valid branch/commit"],"exampleFix":"# before\n$ git rev-parse HEAD\nfatal: ambiguous argument 'HEAD': unknown revision\n\n# after\n$ git add -A && git commit -m 'first commit'\n$ git rev-parse HEAD\n9ae23b5...","handlingStrategy":"validation","validationCode":"// Require a resolvable HEAD before version collection.\nif err := exec.Command(\"git\", \"-C\", dir, \"rev-parse\", \"--verify\", \"HEAD\").Run(); err != nil {\n\treturn fmt.Errorf(\"repo has no commits; commit before building: %w\", err)\n}\nv, err := mkversion.InfoFrom(dir)","typeGuard":"func isGitHashError(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"getting git hash:\")\n}","tryCatchPattern":"v, err := mkversion.InfoFrom(dir)\nif err != nil {\n\tif isGitHashError(err) {\n\t\treturn fmt.Errorf(\"make an initial commit, then rebuild: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Commit before building in fresh repos (CI: fail fast if `git rev-parse HEAD` errors)","Avoid building from repos in a detached/corrupt ref state"],"tags":["git","unborn-branch","build-tooling","mkversion"],"backgroundTag":"unborn-git-branch","analyzedSha":"6e0912f97994f927632b34ae9e63b53d6516a6ac","analyzedAt":"2026-08-18T08:17:25.280Z","contentChangedAt":"2026-08-18T08:17:25.280Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}