Skip to content

Commit bd52a2f

Browse files
committed
fix(sandbox): register /workspace as git safe directory at startup
Git refuses to operate in directories not owned by the current process user. Since /workspace is a bind-mount owned by the host user, the UID mismatch inside the container triggers this check. Register the path via git config safe.directory in the entrypoint before launching OpenCode, covering both the root (gosu) and non-root (--user) startup paths.
1 parent 1e91a8a commit bd52a2f

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

build/entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ if [ "$(id -u)" = "0" ]; then
183183
"${HOST_UID}:${HOST_GID}"
184184
preflight_checks "/home/opencode"
185185

186+
# --- Configure git safe directory ---
187+
# /workspace is a bind-mount owned by the host user. Git refuses to
188+
# operate in directories not owned by the current user, so we register
189+
# /workspace as a safe directory for the opencode user. This must be done
190+
# as root writing to the opencode user's gitconfig before dropping privs.
191+
gosu "$TARGET_USER" git config --global --add safe.directory /workspace 2>/dev/null || true
192+
186193
# --- Drop privileges and launch OpenCode ---
187194
info "Starting OpenCode..."
188195
# gosu replaces this process with the target user — root is gone.
@@ -203,6 +210,10 @@ info "Preparing environment..."
203210
sync_config "$HOME/.config/opencode" "$HOME/.config/opencode.defaults"
204211
preflight_checks "$HOME"
205212

213+
# /workspace is a bind-mount that may be owned by a different UID than the
214+
# container user. Register it as a git safe directory so git commands work.
215+
git config --global --add safe.directory /workspace 2>/dev/null || true
216+
206217
export NVM_DIR="$HOME/.nvm"
207218
# Source nvm.sh to enable `nvm` shell functions (e.g. `nvm install`, `nvm use`).
208219
# The `node` binary itself works without this via the $NVM_DIR/current symlink

0 commit comments

Comments
 (0)