4NK_env/scripts/push-ext-commit.sh
LeCoffre Deployment c0b3bda6da auto_clea
2025-09-25 15:25:14 +00:00

84 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
echo "[push-ext-commit] Ensure all submodules on ext, commit if needed, push ext"
# Work from repo root
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT_DIR"
# Update submodules metadata (non-recursive update of refs; content is already cloned)
git submodule init >/dev/null 2>&1 || true
git submodule foreach --recursive '
set -e
echo "[submodule] Enter: $name ($path)"
# Ensure remote exists
git remote show origin >/dev/null 2>&1 || { echo "[submodule] missing origin remote"; exit 0; }
git config pull.rebase true || true
git fetch --prune origin +refs/heads/*:refs/remotes/origin/* || true
# Ensure local ext tracking origin/ext when available
if git show-ref --verify --quiet refs/remotes/origin/ext; then
if git rev-parse --verify ext >/dev/null 2>&1; then
git switch ext
git branch --set-upstream-to=origin/ext ext || true
else
git switch -C ext origin/ext
fi
else
# Fallback: create ext if missing on remote
if git rev-parse --verify ext >/dev/null 2>&1; then
git switch ext
else
git switch -C ext
fi
fi
# Rebase on remote if present to avoid non-fast-forward
git fetch origin ext || true
git rev-parse --verify origin/ext >/dev/null 2>&1 && git pull --rebase --autostash origin ext || true
# Stage and commit if needed
git add -A
if ! git diff --cached --quiet; then
git commit -m "auto_clea"
fi
# Push with upstream set; handle non-FF by one-time rebase+retry
if ! git push -u origin ext; then
echo "[submodule] push failed, retrying after rebase"
git fetch origin ext || true
git pull --rebase --autostash origin ext || true
git push -u origin ext || echo "[submodule] push still failing for $name"
fi
'
echo "[root] Process root repository"
git config pull.rebase true || true
git fetch --prune origin +refs/heads/*:refs/remotes/origin/* || true
if git show-ref --verify --quiet refs/remotes/origin/ext; then
if git rev-parse --verify ext >/dev/null 2>&1; then
git switch ext
git branch --set-upstream-to=origin/ext ext || true
else
git switch -C ext origin/ext
fi
else
if git rev-parse --verify ext >/dev/null 2>&1; then
git switch ext
else
git switch -C ext
fi
fi
git fetch origin ext || true
git rev-parse --verify origin/ext >/dev/null 2>&1 && git pull --rebase --autostash origin ext || true
git add -A
if ! git diff --cached --quiet; then
git commit -m "auto_clea"
fi
if ! git push -u origin ext; then
echo "[root] push failed, retrying after rebase"
git fetch origin ext || true
git pull --rebase --autostash origin ext || true
git push -u origin ext || echo "[root] push still failing"
fi
echo "[push-ext-commit] Done."