dagger/dagger · error

git apply: %d file(s) could not be patched at all, which con

Error message

git apply: %d file(s) could not be patched at all, which conflict markers cannot express:
%s

What it means

When leaveMarkers is enabled, Dagger can convert per-file rejects into conflict markers, but some failures — a file missing entirely, a binary diff without full index lines — are skipped outright by git apply with nothing written to the tree. Because markers cannot express a wholly-unpatched file, Dagger fails hard listing the files found via wholeFileApplyErrors in stderr.

Source

Thrown at core/directory.go:1847

		return err
	}
	conflicted := make([]string, 0, len(rejects))
	for rej := range rejects {
		if !preexisting[rej] {
			conflicted = append(conflicted, rej)
		}
	}
	if runErr != nil {
		// --reject reports a hunk it could not place and a file it could not
		// patch at all with the same exit status, but only the former leaves
		// a .rej behind. The latter — creating a file that already exists,
		// editing one that is gone, a binary diff without full index lines —
		// is skipped outright, leaving nothing in the tree to show that the
		// change was dropped. The markers below cannot express that, so it
		// stays a failure rather than passing for a conflict whenever some
		// other hunk happened to be rejected as well.
		if failed := wholeFileApplyErrors(stderr.String()); len(failed) > 0 {
			return fmt.Errorf("git apply: %d file(s) could not be patched at all, which conflict markers cannot express:\n%s",
				len(failed), strings.Join(failed, "\n"))
		}
		if len(conflicted) == 0 {
			// No rejects written: a hard failure (bad patch, not a content
			// conflict).
			return fmt.Errorf("git apply: %w", runErr)
		}
	}
	if len(conflicted) == 0 {
		return nil
	}
	sort.Strings(conflicted)
	conflictedTargets := make([]string, 0, len(conflicted))
	for _, rej := range conflicted {
		target := strings.TrimSuffix(rej, ".rej")
		if err := convertRejectToMarkers(filepath.Join(dir, target), filepath.Join(dir, rej)); err != nil {
			return fmt.Errorf("convert %s to conflict markers: %w", rej, err)
		}

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Read the listed file names in the error and check whether each exists in the target directory
  2. Regenerate the patch (including binary index data: git diff --binary) against the target's current state
  3. For intentionally-absent files, remove them from the patch or restructure the change into per-file patches that apply cleanly
  4. Resolve the drift between the patch base and directory contents before applying, e.g. by patching the original base and re-copying

Example fix

// before
git diff > fix.patch  // binary asset added, no --binary flag
// after
git diff --binary > fix.patch // full index lines so git apply can apply binary files
Defensive patterns

Strategy: validation

Validate before calling

// ensure every path the diff touches exists and no binary diffs lack index data
for (const f of diff.filesTouched()) {
  try { await target.file(f).size() } catch { throw new Error(`patched file missing: ${f}`) }
}
// generate patches with: git diff --binary

Try / catch

try {
  await target.patch(patchFile)
} catch (e) {
  if (String(e).includes('could not be patched at all')) {
    const files = String(e).split('\n').slice(1) // list after the header
    throw new Error(`unpatchable files, regenerate diff --binary for: ${files.join(', ')}`)
  }
  throw e
}

Prevention

When it happens

Trigger: Applying a patch (with conflict-marker mode enabled) where git apply reports whole-file failures: the target file does not exist (created/deleted diffs), binary diffs lacking index blobs, or diffs whose paths never resolve inside the directory.

Common situations: Rebase-flavored workflows patching files that were renamed or deleted upstream; patches carrying binary assets without the full binary index; patches produced from a different tree layout than the target directory.

Related errors


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