fix: run git pull as SUDO_USER to use correct SSH keys

This commit is contained in:
Vadym Samoilenko 2026-03-23 14:25:44 +00:00
parent dad8f7573a
commit 16bc9d0c0d

View file

@ -79,15 +79,17 @@ else
fi
# ── 5. Git pull ───────────────────────────────────────────────────────────────
log "Pulling latest code..."
# Run git as the invoking user (not root) so SSH keys work
GIT_USER="${SUDO_USER:-$(whoami)}"
log "Pulling latest code (as $GIT_USER)..."
cd "$APP_DIR"
git fetch origin
sudo -u "$GIT_USER" git fetch origin
LOCAL=$(git rev-parse HEAD)
REMOTE=$(git rev-parse '@{u}')
if [[ "$LOCAL" == "$REMOTE" ]]; then
ok "Already up to date ($(git rev-parse --short HEAD))"
else
git pull --ff-only || die "git pull failed — local changes detected. Stash or reset them first."
sudo -u "$GIT_USER" git pull --ff-only || die "git pull failed — local changes detected. Stash or reset them first."
ok "Updated to $(git rev-parse --short HEAD)"
fi