dagger/dagger · error

failed to pack git checkout for %q: %w

Error message

failed to pack git checkout for %q: %w

What it means

Returned by gitDir in core/schema/host.go when the engine asks the client to pack the git checkout at args.Path (bk.PackGitCheckout) and that fails. The client-side git acts as the oracle for the checkout: this covers the path not being a git repository, git not being installed, the checkout being dirty, or a state-digest mismatch when ValidateState is set. The path is included in the message.

Source

Thrown at core/schema/host.go:849

	if err != nil {
		return inst, err
	}
	bk, err := query.Engine(ctx)
	if err != nil {
		return inst, fmt.Errorf("failed to get engine client: %w", err)
	}

	// args.StateDigest is deliberately unused in the body: it is a pure dagql
	// cache key, keying this reconstruction to the checkout's ref state so the
	// result is reused until the checkout's refs move.

	expectedStateDigest := ""
	if args.ValidateState {
		expectedStateDigest = args.StateDigest
	}
	pack, err := bk.PackGitCheckout(ctx, args.Path, expectedStateDigest)
	if err != nil {
		return inst, fmt.Errorf("failed to pack git checkout for %q: %w", args.Path, err)
	}
	defer func() { _ = pack.Close() }()

	dir, err := core.MaterializeGitCheckoutPack(ctx, pack)
	if err != nil {
		return inst, fmt.Errorf("failed to materialize git checkout pack for %q: %w", args.Path, err)
	}

	srv, err := core.CurrentDagqlServer(ctx)
	if err != nil {
		return inst, fmt.Errorf("failed to get current dagql server: %w", err)
	}
	return dagql.NewObjectResultForCurrentCall(ctx, srv, dir)
}

type hostServiceArgs struct {
	Host  string `default:"localhost"`
	Ports []dagql.InputObject[core.PortForward]

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Run inside an actual git clone ('git clone' the repo, don't unzip an archive) and verify 'git rev-parse --is-inside-work-tree' succeeds in the path
  2. Install git in the environment running the Dagger client ('apt-get install git' / 'apk add git')
  3. If ValidateState is used and refs moved, refresh the state digest from the current checkout (re-run the client so it recomputes) or disable strict validation
  4. Check permissions on the path/.git so the client user can read them

Example fix

// before
# pipeline unzips source.zip and points Host.directory at it
Host.directory("./source") // not a git repo -> pack fails
// after
# clone properly so .git exists
git clone https://github.com/org/repo.git source && dagger run ./pipeline # Host.directory("./source")
Defensive patterns

Strategy: validation

Validate before calling

func isGitWorkTree(path string) error {
    cmd := exec.Command("git", "-C", path, "rev-parse", "--is-inside-work-tree")
    if out, err := cmd.Output(); err != nil || strings.TrimSpace(string(out)) != "true" {
        return fmt.Errorf("%s is not a git work tree (clone it instead of extracting an archive)", path)
    }
    if _, err := exec.LookPath("git"); err != nil {
        return fmt.Errorf("git is not installed on the client host")
    }
    return nil
}
// call isGitWorkTree(path) before Host.directory(path)

Try / catch

dir, err := client.Host().Directory(path)
if err != nil && strings.Contains(err.Error(), "failed to pack git checkout") {
    // path is not a git repo, git missing, or state digest stale: clone properly / refresh digest
}

Prevention

When it happens

Trigger: Host.directory with gitDir reconstruction on: (a) a path that is not inside a git work tree; (b) a machine without git on PATH; (c) a checkout whose refs/state moved so expectedStateDigest no longer matches when args.ValidateState is true; (d) unreadable .git directory.

Common situations: Pointing Dagger at a subdirectory downloaded without .git (zip/tarball extract); shallow or partially cloned repos with unusual states; CI checkouts reusing a stale digest after a rebase/force-push changed refs; missing git in minimal containers running the client.

Related errors


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