🔄 Auto-resolve commit from gitfield-resolve.sh
This commit is contained in:
parent
b60f4f5946
commit
a091f20454
1 changed files with 55 additions and 86 deletions
|
@ -1,103 +1,72 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# gitfield-resolve.sh — 🧠 Recursive GitField Self-Healing Sync Engine
|
|
||||||
# Author: Solaria + Mark Randall Havens 🌀
|
|
||||||
# Version: 𝛂∞.21
|
|
||||||
|
|
||||||
LOG_FILE=".gitfield/last_resolution.log"
|
|
||||||
exec > >(tee "$LOG_FILE") 2>&1
|
|
||||||
|
|
||||||
echo "🛠️ [GITFIELD] Beginning auto-resolution ritual..."
|
echo "🛠️ [GITFIELD] Beginning auto-resolution ritual..."
|
||||||
|
|
||||||
SIGIL_FILES=$(git diff --name-only --diff-filter=U | grep '\.sigil\.md$')
|
# Ensure we’re in a Git repo
|
||||||
PUSHED_LOG=".gitfield/pushed.log"
|
if ! git rev-parse --git-dir > /dev/null 2>&1; then
|
||||||
|
echo "❌ Not a Git repository. Aborting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
resolve_sigil_conflicts() {
|
# Ensure at least one commit exists
|
||||||
for file in $SIGIL_FILES; do
|
if ! git log > /dev/null 2>&1; then
|
||||||
echo "⚖️ Resolving conflict in: $file"
|
echo "🌀 No commits found. Creating seed commit..."
|
||||||
|
git add .
|
||||||
|
git commit --allow-empty -m "🌱 Seed commit for Radicle and GitField rituals"
|
||||||
|
fi
|
||||||
|
|
||||||
OUR_TIME=$(grep -Eo '[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9:]{8}' "$file" | head -n1)
|
# GPG sign commit if enabled
|
||||||
THEIR_TIME=$(grep -Eo '[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9:]{8}' "$file" | tail -n1)
|
GPG_KEY=$(git config user.signingkey)
|
||||||
|
if [ -n "$GPG_KEY" ]; then
|
||||||
|
echo "🔏 GPG commit signing enabled with key: $GPG_KEY"
|
||||||
|
git commit -S --allow-empty -m "🔐 Ritual signed commit [auto]"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "$OUR_TIME" > "$THEIR_TIME" ]]; then
|
# Stage and commit any local changes
|
||||||
echo "🧭 Keeping local version ($OUR_TIME)"
|
if ! git diff --quiet || ! git diff --cached --quiet; then
|
||||||
git checkout --ours "$file"
|
git add .
|
||||||
else
|
git commit -m "🔄 Auto-resolve commit from gitfield-resolve.sh"
|
||||||
echo "🧭 Keeping remote version ($THEIR_TIME)"
|
echo "✅ Local changes committed."
|
||||||
git checkout --theirs "$file"
|
else
|
||||||
fi
|
echo "✅ No changes to commit."
|
||||||
git add "$file"
|
fi
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve_log_conflict() {
|
# Loop through remotes
|
||||||
if [[ -f "$PUSHED_LOG" && $(git ls-files -u | grep "$PUSHED_LOG") ]]; then
|
remotes=$(git remote)
|
||||||
echo "📜 Resolving pushed.log by merging unique lines..."
|
for remote in $remotes; do
|
||||||
git checkout --ours "$PUSHED_LOG"
|
echo "🔍 Checking $remote for divergence..."
|
||||||
cp "$PUSHED_LOG" .log_ours
|
git fetch $remote
|
||||||
|
if git merge-base --is-ancestor $remote/master master; then
|
||||||
git checkout --theirs "$PUSHED_LOG"
|
echo "✅ $remote is already in sync."
|
||||||
cp "$PUSHED_LOG" .log_theirs
|
|
||||||
|
|
||||||
cat .log_ours .log_theirs | sort | uniq > "$PUSHED_LOG"
|
|
||||||
rm .log_ours .log_theirs
|
|
||||||
|
|
||||||
git add "$PUSHED_LOG"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
commit_resolution() {
|
|
||||||
if git diff --cached --quiet; then
|
|
||||||
echo "✅ No changes to commit."
|
|
||||||
else
|
else
|
||||||
echo "🖋️ Committing auto-resolved changes with GPG signature..."
|
echo "⚠️ Divergence with $remote. Attempting merge..."
|
||||||
git commit -S -m "🔄 Auto-resolved sigil + log conflicts via gitfield-resolve"
|
git pull --no-rebase $remote master --strategy-option=theirs --allow-unrelated-histories
|
||||||
|
git push $remote master || echo "⚠️ Final push failed to $remote"
|
||||||
fi
|
fi
|
||||||
}
|
done
|
||||||
|
|
||||||
check_and_sync_remotes() {
|
# ==== RADICLE SECTION ====
|
||||||
for remote in $(git remote); do
|
|
||||||
echo "🔍 Checking $remote for divergence..."
|
|
||||||
git fetch "$remote" master
|
|
||||||
|
|
||||||
BASE=$(git merge-base master "$remote/master")
|
echo "🌱 [RADICLE] Verifying Radicle status..."
|
||||||
LOCAL=$(git rev-parse master)
|
|
||||||
REMOTE=$(git rev-parse "$remote/master")
|
|
||||||
|
|
||||||
if [ "$LOCAL" = "$REMOTE" ]; then
|
# Check if Radicle is initialized
|
||||||
echo "✅ $remote is already in sync."
|
if ! rad inspect > /dev/null 2>&1; then
|
||||||
elif [ "$LOCAL" = "$BASE" ]; then
|
echo "🌿 No Radicle project detected. Attempting init..."
|
||||||
echo "⬇️ Local is behind $remote. Pulling changes..."
|
RAD_INIT_OUTPUT=$(rad init --name git-sigil --description "GitField Ritual Repo")
|
||||||
git pull --no-rebase "$remote" master || echo "⚠️ Pull failed for $remote"
|
echo "$RAD_INIT_OUTPUT"
|
||||||
resolve_sigil_conflicts
|
fi
|
||||||
resolve_log_conflict
|
|
||||||
commit_resolution
|
|
||||||
git push "$remote" master || echo "⚠️ Push failed to $remote"
|
|
||||||
elif [ "$REMOTE" = "$BASE" ]; then
|
|
||||||
echo "⬆️ Local is ahead of $remote. Pushing..."
|
|
||||||
git push "$remote" master || echo "⚠️ Push failed to $remote"
|
|
||||||
else
|
|
||||||
echo "⚠️ Divergence with $remote. Attempting merge..."
|
|
||||||
git pull --no-rebase "$remote" master || echo "❌ Merge failed: Manual fix required."
|
|
||||||
resolve_sigil_conflicts
|
|
||||||
resolve_log_conflict
|
|
||||||
commit_resolution
|
|
||||||
git push "$remote" master || echo "⚠️ Final push failed to $remote"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
final_force_github() {
|
# Push to Radicle and announce
|
||||||
if git remote get-url github &>/dev/null; then
|
echo "📡 Announcing to Radicle network..."
|
||||||
echo "🧙 Final override: Forcing sync to GitHub..."
|
rad push --announce
|
||||||
git push --force github master && echo "✅ GitHub forcibly realigned with local truth." || echo "❌ Force push failed. Manual intervention required."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# --- Ritual Sequence ---
|
# Get project ID
|
||||||
resolve_sigil_conflicts
|
PROJECT_ID=$(rad inspect | grep "Project ID" | awk '{print $NF}')
|
||||||
resolve_log_conflict
|
if [ -n "$PROJECT_ID" ]; then
|
||||||
commit_resolution
|
echo "📜 Logging Radicle project ID to .gitfield/radicle.sigil.md"
|
||||||
check_and_sync_remotes
|
mkdir -p .gitfield
|
||||||
final_force_github
|
echo "# Radicle Sigil" > .gitfield/radicle.sigil.md
|
||||||
|
echo "**Project ID:** \`$PROJECT_ID\`" >> .gitfield/radicle.sigil.md
|
||||||
|
fi
|
||||||
|
|
||||||
echo "✅ GitField resolution ritual complete."
|
echo "✅ GitField resolution ritual complete."
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue