#!/usr/bin/env bash set -euo pipefail echo "[push-ext-commit] Ensure all submodules on ext, commit if needed, push ext" PUSH_FORCE=${PUSH_FORCE:-0} push_branch_ext() { # Always push explicit branch refspec to avoid conflicts with tag 'ext' if ! git push -u origin refs/heads/ext:refs/heads/ext; then echo "[push] branch push failed, retrying after rebase" git fetch origin ext || true git pull --rebase --autostash origin ext || true if ! git push -u origin refs/heads/ext:refs/heads/ext; then if [ "$PUSH_FORCE" = "1" ]; then echo "[push] forcing with lease (branch ext)" git push --force-with-lease -u origin refs/heads/ext:refs/heads/ext || return 1 else echo "[push] still failing (set PUSH_FORCE=1 to force)"; return 1 fi fi fi } # 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 # Ensure we are on ext branch (and not a symbolic heads/ext anomaly) cur_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo ext) if [ "$cur_branch" != "ext" ]; then # Try to rename if local ref exists as refs/heads/ext if git show-ref --verify --quiet refs/heads/ext; then git switch ext || git branch -m "$cur_branch" ext || true; fi fi push_branch_ext || echo "[submodule] push encountered errors for $name" ' 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 # Root push (explicit refspec to avoid tag/branch confusion) push_branch_ext || echo "[root] push encountered errors" echo "[push-ext-commit] Done."