dagger/dagger · error

failed to load git dir: %w

Error message

failed to load git dir: %w

What it means

gitModuleSource selects the `tree` field on the resolved gitRef to materialize the repository contents into a Directory (gitSrc.ContextDirectory). If that dagql selection fails, the error is wrapped as 'failed to load git dir'. The git ref resolved, but its file tree could not be produced.

Source

Thrown at core/schema/modulesource.go:790

		ConfigFilename: modules.Filename,
		Kind:           core.ModuleSourceKindGit,
		Git: &core.GitModuleSource{
			HTMLRepoURL:  parsed.RepoRoot.Repo,
			RepoRootPath: parsed.RepoRoot.Root,
			Version:      cmp.Or(gitRef.Self().Ref.ShortName(), gitRef.Self().Ref.SHA),
			Commit:       gitRef.Self().Ref.SHA,
			Ref:          gitRef.Self().Ref.Name,
			CloneRef:     parsed.SourceCloneRef,
		},
	}

	// TODO:(sipsma) support sparse loading of git repos similar to how local dirs are loaded.
	// Related: https://github.com/dagger/dagger/issues/6292
	err = dag.Select(ctx, gitRef, &gitSrc.ContextDirectory,
		dagql.Selector{Field: "tree"},
	)
	if err != nil {
		return inst, fmt.Errorf("failed to load git dir: %w", err)
	}
	gitSrc.Git.UnfilteredContextDir = gitSrc.ContextDirectory

	gitSrc.SourceRootSubpath = strings.TrimPrefix(parsed.RepoRootSubdir, "/")
	gitSrc.OriginalSubpath = gitSrc.SourceRootSubpath

	_, configFound, err := s.findGitModuleConfig(ctx, gitSrc, doFindUp, allowNotExists)
	if err != nil {
		return inst, err
	}
	if gitSrc.SourceRootSubpath == "" {
		gitSrc.SourceRootSubpath = "."
	}

	gitSrc.Git.Symbolic = gitSrc.Git.CloneRef
	if gitSrc.SourceRootSubpath != "." {
		gitSrc.Git.Symbolic += "/" + gitSrc.SourceRootSubpath
	}

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Retry — transient fetch failures are common
  2. Verify the ref is fetchable: git clone at the same commit in your environment
  3. Check for git host rate limits or proxy interference
  4. Reduce scope (narrow subpath/ref) or use a local module source if repo size is the issue
Defensive patterns

Strategy: retry

Validate before calling

// Force the tree to materialize before module load
await client.git(repoUrl).ref(ref).tree().id();

Try / catch

try {
  const mod = await client.moduleSource(gitRef).load();
} catch (e) {
  if (String(e).includes("failed to load git dir")) {
    // retry; check network/rate limits if persistent
  }
  throw e;
}

Prevention

When it happens

Trigger: dag.Select(ctx, gitRef, &gitSrc.ContextDirectory, Selector{Field: "tree"}) fails — e.g. failure fetching objects for the ref, shallow/partial clone issues, or engine error building the tree Directory for a large/unusual repo.

Common situations: Very large repos hitting fetch/size limits; flaky network mid-fetch; git host rate-limiting the engine; pinned commit not fully available on the fetched remote.

Related errors


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