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

  1. Ensure the GitRepository was initialized and its Remote() returned a non-nil value before calling this
  2. Check for earlier errors that left the remote nil but were swallowed
  3. Guard the call site: if remote == nil, initialize or return a clearer upstream error
  4. 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

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


AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05). Data as JSON: /api/errors/e2695cc82000b87f. Report an issue: GitHub.