dagger/dagger · error
select latest git ref: nil remote
Error message
select latest git ref: nil remote
What it means
This error is returned by SelectLatestGitRefWithTagPrefix when the provided *gitutil.Remote is nil. The library throws it because ref lookups require a live remote; a nil remote means no repository source to query.
Source
Thrown at core/git.go:100
mount(ctx context.Context, depth int, includeTags bool, fn func(*gitutil.GitCLI) error) error
}
// SelectLatestGitRef selects the greatest stable release tag in remote after
// normalizing optional v prefixes, incomplete versions, and zero-padded numeric
// components. It falls back to HEAD when no eligible release tag exists.
func SelectLatestGitRef(remote *gitutil.Remote) (*gitutil.Ref, error) {
return SelectLatestGitRefWithTagPrefix(remote, "")
}
// SelectLatestGitRefWithTagPrefix selects the greatest normalized stable
// release tag below tagPrefix. If no matching prefixed release exists,
// repository-wide release tags are considered before falling back to HEAD.
func SelectLatestGitRefWithTagPrefix(
remote *gitutil.Remote,
tagPrefix string,
) (*gitutil.Ref, error) {
if remote == nil {
return nil, fmt.Errorf("select latest git ref: nil remote")
}
tagPrefix = strings.Trim(tagPrefix, "/")
if tagPrefix != "" {
tagPrefix += "/"
}
bestRef, err := selectLatestGitRelease(remote, tagPrefix)
if err != nil {
return nil, err
}
if bestRef == "" && tagPrefix != "" {
bestRef, err = selectLatestGitRelease(remote, "")
if err != nil {
return nil, err
}
}
View on GitHub (pinned to 82ba2681db)
Solutions
- Ensure the GitRepository was initialized and its Remote() returned a non-nil value before calling this
- Check for earlier errors that left the remote nil but were swallowed
- Guard the call site: if remote == nil, initialize or return a clearer upstream error
- Add a test covering the uninitialized-repository path
Example fix
// before
ref, err := SelectLatestGitRef(repo.remote, "v") // remote is nil
// after
if repo.remote == nil {
return nil, fmt.Errorf("repository has no remote; was it loaded?")
}
ref, err := SelectLatestGitRef(repo.remote, "v") Defensive patterns
Strategy: validation
Validate before calling
if remote == nil {
return nil, fmt.Errorf("cannot select latest ref: remote not initialized")
}
ref, err := SelectLatestGitRefWithTagPrefix(remote, prefix) Type guard
func hasRemote(r *gitutil.Remote) bool { return r != nil } Try / catch
ref, err := SelectLatestGitRef(repo.Remote())
if err != nil {
if err.Error() == "select latest git ref: nil remote" {
return nil, fmt.Errorf("repository not loaded; call clone/load first")
}
return err
} Prevention
- Always check GitRepository.Remote() / upstream errors before use
- Initialize the repository (load/clone) before ref operations
- Surface early errors instead of passing nil remotes downstream
- Add a test for the uninitialized repository path
When it happens
Trigger: Calling SelectLatestGitRef / SelectLatestGitRefWithTagPrefix with a remote value that was never initialized (e.g. an upstream Remote() call returned nil and was passed through unchecked).
Common situations: GitRepository not yet loaded/cloned so its remote handle is unset; error path earlier returned nil remote without surfacing; test harness omitted remote setup.
Related errors
- resolve git remote HEAD: %w
- resolve latest git release %q: %w
- invalid git-latest tag %q: not a semantic version
- invalid git-latest tag %q: prerelease tags are not supported
- invalid git-latest ref %q
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/e2695cc82000b87f.
Report an issue: GitHub.