auto_clea
This commit is contained in:
parent
b925dfabc9
commit
62736e60e9
@ -1,97 +1,27 @@
|
||||
#!/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
|
||||
# Quiet script: always force-with-lease push branch ext (avoid tag/branch ext clash)
|
||||
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
|
||||
push_ext_quiet() {
|
||||
git remote show origin >/dev/null 2>&1 || return 0
|
||||
git fetch -q --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
|
||||
git rev-parse --verify ext >/dev/null 2>&1 || git switch -q -C ext origin/ext
|
||||
git branch --set-upstream-to=origin/ext ext >/dev/null 2>&1 || true
|
||||
else
|
||||
git switch -C ext origin/ext
|
||||
git rev-parse --verify ext >/dev/null 2>&1 || git switch -q -C 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"
|
||||
'
|
||||
git switch -q ext || true
|
||||
git add -A >/dev/null 2>&1 || true
|
||||
git diff --cached --quiet || git commit -m "auto_clea" >/dev/null 2>&1 || true
|
||||
git push --force-with-lease -u origin refs/heads/ext:refs/heads/ext >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
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"
|
||||
# Submodules
|
||||
git submodule foreach --recursive 'set -e; git remote show origin >/dev/null 2>&1 || exit 0; git fetch -q --prune origin +refs/heads/*:refs/remotes/origin/* || true; if git show-ref --verify --quiet refs/remotes/origin/ext; then git rev-parse --verify ext >/dev/null 2>&1 || git switch -q -C ext origin/ext; git branch --set-upstream-to=origin/ext ext >/dev/null 2>&1 || true; else git rev-parse --verify ext >/dev/null 2>&1 || git switch -q -C ext; fi; git switch -q ext || true; git add -A >/dev/null 2>&1 || true; git diff --cached --quiet || git commit -m "auto_clea" >/dev/null 2>&1 || true; git push --force-with-lease -u origin refs/heads/ext:refs/heads/ext >/dev/null 2>&1 || true' >/dev/null 2>&1 || true
|
||||
|
||||
echo "[push-ext-commit] Done."
|
||||
# Root
|
||||
push_ext_quiet
|
||||
|
Loading…
x
Reference in New Issue
Block a user