dagger/dagger · error
error getting reference %q: %w
Error message
error getting reference %q: %w
What it means
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.
Source
Thrown at engine/telemetry/labels.go:607
// breaking subsequent git history operations (merge-base, describe, ...).
args := []string{"fetch"}
if isShallowRepo(workdir) {
args = append(args, "--depth", "1")
}
args = append(args, remote, fmt.Sprintf("+%s:%s", src, dest))
// Fetch from the origin remote
cmd := exec.Command("git", args...)
cmd.Dir = workdir
out, err := cmd.CombinedOutput()
if err != nil {
return nil, fmt.Errorf("error fetching branch from origin: %w\n%s", err, string(out))
}
// Get the reference of the fetched branch
ref, err := repo.Reference(plumbing.ReferenceName(dest), true)
if err != nil {
return nil, fmt.Errorf("error getting reference %q: %w", dest, err)
}
// Get the commit object of the fetched branch
branchCommit, err := repo.CommitObject(ref.Hash())
if err != nil {
return nil, fmt.Errorf("error getting commit %q: %w", ref.Hash(), err)
}
// Cleanup the temp ref
cmd = exec.Command("git", "update-ref", "-d", dest, ref.Hash().String())
cmd.Dir = workdir
out, err = cmd.CombinedOutput()
if err != nil {
err = fmt.Errorf("error deleting ref %q: %w\n%s", dest, err, out)
slog.Warn("failed to cleanup temp ref", "err", err)
}
return branchCommit, nilView on GitHub (pinned to 82ba2681db)
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>).
Example fix
// before
ref, err := repo.Reference(plumbing.ReferenceName(dest), true)
// after (fallback lookup)
ref, err := repo.Reference(plumbing.ReferenceName(dest), true)
if err != nil {
ref, err = repo.Reference(plumbing.ReferenceName("refs/remotes/origin/"+branch), true)
} Defensive patterns
Strategy: validation
Validate before calling
// confirm ref naming before lookup
func validRemoteRef(branch string) bool {
return strings.HasPrefix(branch, "refs/") || branch != ""
} Try / catch
ref, err := repo.Reference(plumbing.ReferenceName(dest), true)
if err != nil {
slog.Warn("ref not found after fetch", "dest", dest)
return nil, err // or fall back to another ref naming scheme
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- invalid git-latest ref %q
- failed to delete tmp ref: %w
- error getting commit %q: %w
- failed to generate patch: %w
- remove temporary octopus merge git repository: %w
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/c0c681e76f8c97fb.
Report an issue: GitHub.