Merge pull request #469 from samcharles93/fix/dubious-ownership-agent-container

fix(agent): resolve git dubious-ownership in sandbox containers
This commit is contained in:
sam authored and GitHub committed 2026-08-12 16:13:05 +10:00
commit 2ed4e14127
1 file changed
+15
+15
View File
@@ -21,6 +21,7 @@ import (
"fmt"
"log/slog"
"os"
"os/exec"
"os/signal"
"path/filepath"
"strings"
@@ -77,6 +78,20 @@ func run() int {
log := slog.New(slog.NewJSONHandler(os.Stderr, nil))
// Worktrees are bind-mounted from the host into the container at
// /data/worktree. The host-side UID that owns the worktree differs
// from the container user's UID. Git refuses to operate when the
// containing directory is owned by another user ("fatal: detected
// dubious ownership in repository"). The Go toolchain calls git for
// VCS status during go build/test/vet, so every gate fails before
// any real work begins. Marking the mount directory as safe resolves
// this for the container's lifetime.
gitSafeDir := exec.Command("git", "config", "--global", "--add", "safe.directory", storage.WorktreeMountDir)
if out, gitErr := gitSafeDir.CombinedOutput(); gitErr != nil {
log.Warn("git safe.directory config failed (gate commands that shell out to git may encounter dubious-ownership errors)",
"dir", storage.WorktreeMountDir, "err", gitErr, "output", string(out))
}
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()