{"record":{"id":"c0c681e76f8c97fb","repo":"dagger/dagger","slug":"error-getting-reference-q-w","errorCode":null,"errorMessage":"error getting reference %q: %w","messagePattern":"error getting reference %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/telemetry/labels.go","lineNumber":607,"sourceCode":"\t// breaking subsequent git history operations (merge-base, describe, ...).\n\targs := []string{\"fetch\"}\n\tif isShallowRepo(workdir) {\n\t\targs = append(args, \"--depth\", \"1\")\n\t}\n\targs = append(args, remote, fmt.Sprintf(\"+%s:%s\", src, dest))\n\n\t// Fetch from the origin remote\n\tcmd := exec.Command(\"git\", args...)\n\tcmd.Dir = workdir\n\tout, err := cmd.CombinedOutput()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error fetching branch from origin: %w\\n%s\", err, string(out))\n\t}\n\n\t// Get the reference of the fetched branch\n\tref, err := repo.Reference(plumbing.ReferenceName(dest), true)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error getting reference %q: %w\", dest, err)\n\t}\n\n\t// Get the commit object of the fetched branch\n\tbranchCommit, err := repo.CommitObject(ref.Hash())\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error getting commit %q: %w\", ref.Hash(), err)\n\t}\n\n\t// Cleanup the temp ref\n\tcmd = exec.Command(\"git\", \"update-ref\", \"-d\", dest, ref.Hash().String())\n\tcmd.Dir = workdir\n\tout, err = cmd.CombinedOutput()\n\tif err != nil {\n\t\terr = fmt.Errorf(\"error deleting ref %q: %w\\n%s\", dest, err, out)\n\t\tslog.Warn(\"failed to cleanup temp ref\", \"err\", err)\n\t}\n\n\treturn branchCommit, nil","sourceCodeStart":589,"sourceCodeEnd":625,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/engine/telemetry/labels.go#L589-L625","documentation":"After a successful `git fetch`, fetchRef looks up the fetched reference with go-git's repo.Reference(plumbing.ReferenceName(dest), true). If the ref cannot be resolved, the error is wrapped as \"error getting reference %q: %w\" with the destination ref name. This means the fetch succeeded but the expected local ref was not created or cannot be resolved.","triggerScenarios":"repo.Reference(dest, true) fails right after fetching — dest ref name doesn't match what the fetch wrote, the fetch refspec mapped elsewhere, or a shallow/partial clone omitted the ref.","commonSituations":"Mismatch between the fetch destination and the ref name looked up; go-git ref storage out of sync after external git commands mutated .git; empty or invalid ref name derived from the PR head.","solutions":["Compare the %q ref name in the error with the actual refs (`git show-ref | grep <name>`) in the workdir.","Ensure the git fetch refspec actually writes to the `dest` reference used in the lookup.","Run `go-git` storage refresh or re-open the repository after external git commands.","Validate the ref name format before calling (e.g. refs/remotes/origin/<branch>)."],"exampleFix":"// before\nref, err := repo.Reference(plumbing.ReferenceName(dest), true)\n// after (fallback lookup)\nref, err := repo.Reference(plumbing.ReferenceName(dest), true)\nif err != nil {\n    ref, err = repo.Reference(plumbing.ReferenceName(\"refs/remotes/origin/\"+branch), true)\n}","handlingStrategy":"validation","validationCode":"// confirm ref naming before lookup\nfunc validRemoteRef(branch string) bool {\n    return strings.HasPrefix(branch, \"refs/\") || branch != \"\"\n}","typeGuard":null,"tryCatchPattern":"ref, err := repo.Reference(plumbing.ReferenceName(dest), true)\nif err != nil {\n    slog.Warn(\"ref not found after fetch\", \"dest\", dest)\n    return nil, err // or fall back to another ref naming scheme\n}","preventionTips":["Keep fetch destination and lookup ref name in sync (single constant).","After external git commands mutate .git, re-open the go-git repo.","Use fully-qualified ref names (refs/remotes/origin/<branch>).","Verify with `git show-ref` when debugging."],"tags":["git","go-git","refs"],"backgroundTag":"git-ref-not-found","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}