@@ -302,19 +302,30 @@ jobs:
302302 shell : bash
303303 run : |
304304 set -euo pipefail
305- cd "$GITHUB_WORKSPACE"
306- git checkout -b "${{ steps.branch.outputs.name }}"
305+ unset GIT_DIR GIT_WORK_TREE || true
306+ git -C "$GITHUB_WORKSPACE" checkout -b "${{ steps.branch.outputs.name }}"
307307
308- - name : Apply delta (OLD render → NEW render) to repo
308+ - name : Apply delta (OLD render → NEW render) to repo (protect .git)
309309 shell : bash
310310 run : |
311311 set -euo pipefail
312312 cd "$GITHUB_WORKSPACE"
313313
314+ # If .git is missing here, commit will never work—fail early with context
315+ if [ ! -e ".git" ]; then
316+ echo "::error ::.git is missing in workspace before delta apply."
317+ pwd
318+ ls -la
319+ exit 1
320+ fi
321+
322+ rm -rf /tmp/workspace_git || true
323+ mv .git /tmp/workspace_git
324+
314325 OLD_ROOT="${{ steps.render_old.outputs.project_root }}"
315326 NEW_ROOT="${{ steps.render_new.outputs.project_root }}"
316327
317- RSYNC_EXCLUDES=(--exclude ".git/")
328+ RSYNC_EXCLUDES=(--exclude ".git" --exclude ".git /")
318329
319330 if [ "${{ steps.auth.outputs.enabled }}" != "true" ]; then
320331 RSYNC_EXCLUDES+=(--exclude ".github/workflows/")
@@ -342,13 +353,14 @@ jobs:
342353 done < <(find . -type f -print)
343354
344355 cd "$GITHUB_WORKSPACE"
356+ mv /tmp/workspace_git .git
357+
358+ git rev-parse --is-inside-work-tree
345359
346360 - name : Update .cookiecutter.json
347361 shell : bash
348362 run : |
349363 set -euo pipefail
350- cd "$GITHUB_WORKSPACE"
351-
352364 cp /tmp/replay.pruned.json "$GITHUB_WORKSPACE/.cookiecutter.json"
353365
354366 NEW_SHA="${{ needs.check-update.outputs.new_sha }}"
@@ -361,22 +373,22 @@ jobs:
361373 shell : bash
362374 run : |
363375 set -euo pipefail
364- cd "$GITHUB_WORKSPACE"
376+ unset GIT_DIR GIT_WORK_TREE || true
365377
366378 OLD_SHA="${{ needs.check-update.outputs.old_sha }}"
367379 NEW_SHA="${{ needs.check-update.outputs.new_sha }}"
368380
369- git config user.name "GitHub Actions Bot"
370- git config user.email "actions@github.com"
371- git add -A
381+ git -C "$GITHUB_WORKSPACE" config user.name "GitHub Actions Bot"
382+ git -C "$GITHUB_WORKSPACE" config user.email "actions@github.com"
383+ git -C "$GITHUB_WORKSPACE" add -A
372384
373- if git diff --cached --quiet; then
385+ if git -C "$GITHUB_WORKSPACE" diff --cached --quiet; then
374386 echo "No changes; skipping PR."
375387 echo "has_changes=false" >> "$GITHUB_OUTPUT"
376388 exit 0
377389 fi
378390
379- git commit -m "chore: update from template ${OLD_SHA} → ${NEW_SHA}"
391+ git -C "$GITHUB_WORKSPACE" commit -m "chore: update from template ${OLD_SHA} → ${NEW_SHA}"
380392 echo "has_changes=true" >> "$GITHUB_OUTPUT"
381393
382394 - name : Push branch and create PR
@@ -386,13 +398,13 @@ jobs:
386398 GH_TOKEN : ${{ steps.auth.outputs.token }}
387399 run : |
388400 set -euo pipefail
389- cd "$GITHUB_WORKSPACE"
401+ unset GIT_DIR GIT_WORK_TREE || true
390402
391403 OLD_SHA="${{ needs.check-update.outputs.old_sha }}"
392404 NEW_SHA="${{ needs.check-update.outputs.new_sha }}"
393405 BRANCH="${{ steps.branch.outputs.name }}"
394406
395- git push -u origin "$BRANCH"
407+ git -C "$GITHUB_WORKSPACE" push -u origin "$BRANCH"
396408
397409 gh pr create \
398410 --title "chore: update from template ${OLD_SHA} → ${NEW_SHA}" \
0 commit comments