Skip to content

Commit feb5d4a

Browse files
authored
Merge pull request #22 from touchmegit1/dev
fix: enhance git sync process with sudo to handle permission issues a…
2 parents 90a83b8 + 4d364fa commit feb5d4a

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

.github/workflows/cd.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)