fix: run git pull as SUDO_USER to use correct SSH keys
This commit is contained in:
parent
dad8f7573a
commit
16bc9d0c0d
1 changed files with 5 additions and 3 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue