dagger/dagger · error

encode persisted git commit: missing ref

Error message

encode persisted git commit: missing ref

What it means

Thrown by GitCommit.EncodePersistedObject when the commit's embedded Ref pointer is nil. A GitCommit derives its SHA and identity from its gitutil.Ref, so without a Ref the commit cannot be serialized into the persisted-object payload.

Source

Thrown at core/git.go:643

		Repo:    repo,
		Backend: backend,
		Ref:     ref,
	}, nil
}

type persistedGitCommitPayload struct {
	RepoResultID uint64 `json:"repoResultID"`
	SHA          string `json:"sha"`
	FetchName    string `json:"fetchName,omitempty"`
}

func (commit *GitCommit) EncodePersistedObject(ctx context.Context, cache dagql.PersistedObjectCache) (dagql.PersistedObjectEncoding, error) {
	_ = ctx
	if commit == nil {
		return dagql.PersistedObjectEncoding{}, fmt.Errorf("encode persisted git commit: nil commit")
	}
	if commit.Ref == nil {
		return dagql.PersistedObjectEncoding{}, fmt.Errorf("encode persisted git commit: missing ref")
	}
	if commit.Ref.SHA == "" {
		return dagql.PersistedObjectEncoding{}, fmt.Errorf("encode persisted git commit: missing commit SHA")
	}
	repoID, err := encodePersistedObjectRef(cache, commit.Repo, "git commit repo")
	if err != nil {
		return dagql.PersistedObjectEncoding{}, err
	}
	fetchName := ""
	if commit.FetchRef != nil {
		fetchName = commit.FetchRef.Name
	}
	payloadJSON, err := json.Marshal(persistedGitCommitPayload{
		RepoResultID: repoID,
		SHA:          commit.Ref.SHA,
		FetchName:    fetchName,
	})
	if err != nil {

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Set commit.Ref = &gitutil.Ref{SHA: <sha>} (and Name for refs) before encoding
  2. Construct commits via the dagql GitRepository APIs so Ref is populated automatically
  3. Add a pre-encode validation: if commit.Ref == nil { return descriptive error }
  4. Trace where the commit was created and ensure the branch/tag/commit resolution assigns Ref

Example fix

// before
commit := &GitCommit{Repo: repo}
enc, err := commit.EncodePersistedObject(ctx, cache) // missing ref
// after
commit := &GitCommit{Repo: repo, Ref: &gitutil.Ref{SHA: sha}}
enc, err := commit.EncodePersistedObject(ctx, cache)
Defensive patterns

Strategy: validation

Validate before calling

if commit == nil || commit.Ref == nil {
	return fmt.Errorf("GitCommit requires a populated Ref before encoding")
}

Type guard

func commitHasRef(c *GitCommit) bool { return c != nil && c.Ref != nil }

Try / catch

enc, err := commit.EncodePersistedObject(ctx, cache)
if err != nil {
	return fmt.Errorf("persist git commit: %w", err)
}

Prevention

When it happens

Trigger: Encoding a *GitCommit that has Repo set but Ref left nil — e.g. manual construction, or a decode path that built a commit without attaching its Ref.

Common situations: Hand-assembled GitCommit structs in custom tooling; refactors that changed how Ref is attached; partial initialization after DecodePersistedObject changes.

Related errors


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