From 68a4e1b487e41a4195c6be3f66ff0477449fd7c3 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sun, 25 Oct 2026 21:58:25 +1100 Subject: [PATCH] fix(storage): mount a task's object mirror read-only into its container --- internal/storage/storage.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/internal/storage/storage.go b/internal/storage/storage.go index dd79af6da..b214cdd23 100644 --- a/internal/storage/storage.go +++ b/internal/storage/storage.go @@ -44,6 +44,7 @@ type Mount struct { Source string // host path (bind) or volume name (volume) Destination string // container path Shared bool // bind source is intentionally shared between containers + ReadOnly bool } // Mount type constants. @@ -280,6 +281,11 @@ func (d *DockerBackend) Setup(ctx context.Context, task TaskRef) ([]Mount, error Destination: WorktreeMountDir, }, } + // A worktree cloned from a shared mirror reads its objects through the + // mirror's host path, so git in the container needs that path too. + if mirror := alternatesSource(task.WorktreeDir); mirror != "" { + mounts = append(mounts, Mount{Type: MountTypeBind, Source: mirror, Destination: mirror, Shared: true, ReadOnly: true}) + } // Per-repo persistent volume. if task.PersistentStorage && task.Owner != "" && task.Repo != "" { @@ -361,10 +367,25 @@ func ConvertMounts(mounts []Mount) []mount.Mount { out := make([]mount.Mount, len(mounts)) for i, m := range mounts { out[i] = mount.Mount{ - Type: mount.Type(m.Type), - Source: m.Source, - Target: m.Destination, + Type: mount.Type(m.Type), + Source: m.Source, + Target: m.Destination, + ReadOnly: m.ReadOnly, } } return out } + +// alternatesSource returns the repository directory that the worktree's +// alternates file borrows objects from, or "" when it borrows none. +func alternatesSource(worktree string) string { + data, err := os.ReadFile(filepath.Join(worktree, ".git", "objects", "info", "alternates")) + if err != nil { + return "" + } + objects := strings.TrimSpace(strings.SplitN(string(data), "\n", 2)[0]) + if !filepath.IsAbs(objects) { + return "" + } + return filepath.Dir(objects) +}