File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed
Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -179,16 +179,17 @@ jobs:
179179 git config --global --add safe.directory "$DEPLOY_PATH" || true
180180 sudo git config --system --add safe.directory "$DEPLOY_PATH" || true
181181
182- # Try normal git first; fallback to sudo git when .git is root-owned.
183- if git -C "$DEPLOY_PATH" fetch origin; then
184- git -C "$DEPLOY_PATH" checkout main
185- git -C "$DEPLOY_PATH" pull --ff-only origin main
186- else
187- echo "Normal git fetch failed, retry with sudo git..."
188- sudo git -C "$DEPLOY_PATH" fetch origin
189- sudo git -C "$DEPLOY_PATH" checkout main
190- sudo git -C "$DEPLOY_PATH" pull --ff-only origin main
182+ # Always sync with sudo git to avoid permission issues on root-owned .git.
183+ # Preserve local VM edits in a stash, then force working tree to origin/main.
184+ if ! sudo git -C "$DEPLOY_PATH" diff --quiet || ! sudo git -C "$DEPLOY_PATH" diff --cached --quiet; then
185+ STASH_NAME="auto-deploy-$(date +%s)"
186+ echo "Local changes detected on VM. Stashing as: $STASH_NAME"
187+ sudo git -C "$DEPLOY_PATH" stash push -u -m "$STASH_NAME" || true
191188 fi
189+
190+ sudo git -C "$DEPLOY_PATH" fetch origin
191+ sudo git -C "$DEPLOY_PATH" checkout main
192+ sudo git -C "$DEPLOY_PATH" reset --hard origin/main
192193 fi
193194
194195 if [ ! -f "$ENV_FILE" ]; then
You can’t perform that action at this time.
0 commit comments