/ bin / gitfield-resolve.sh
gitfield-resolve.sh
 1  #!/bin/bash
 2  
 3  echo "πŸ› οΈ [GITFIELD] Beginning auto-resolution ritual..."
 4  
 5  # Ensure we’re in a Git repo
 6  if ! git rev-parse --git-dir > /dev/null 2>&1; then
 7    echo "❌ Not a Git repository. Aborting."
 8    exit 1
 9  fi
10  
11  # Ensure at least one commit exists
12  if ! git log > /dev/null 2>&1; then
13    echo "πŸŒ€ No commits found. Creating seed commit..."
14    git add .
15    git commit --allow-empty -m "🌱 Seed commit for Radicle and GitField rituals"
16  fi
17  
18  # GPG sign commit if enabled
19  GPG_KEY=$(git config user.signingkey)
20  if [ -n "$GPG_KEY" ]; then
21    echo "πŸ” GPG commit signing enabled with key: $GPG_KEY"
22    git commit -S --allow-empty -m "πŸ” Ritual signed commit [auto]"
23  fi
24  
25  # Stage and commit any local changes
26  if ! git diff --quiet || ! git diff --cached --quiet; then
27    git add .
28    git commit -m "πŸ”„ Auto-resolve commit from gitfield-resolve.sh"
29    echo "βœ… Local changes committed."
30  else
31    echo "βœ… No changes to commit."
32  fi
33  
34  # Loop through remotes
35  remotes=$(git remote)
36  for remote in $remotes; do
37    echo "πŸ” Checking $remote for divergence..."
38    git fetch $remote
39    if git merge-base --is-ancestor $remote/master master; then
40      echo "βœ… $remote is already in sync."
41    else
42      echo "⚠️ Divergence with $remote. Attempting merge..."
43      git pull --no-rebase $remote master --strategy-option=theirs --allow-unrelated-histories
44      git push $remote master || echo "⚠️ Final push failed to $remote"
45    fi
46  done
47  
48  # ==== RADICLE SECTION ====
49  
50  echo "🌱 [RADICLE] Verifying Radicle status..."
51  
52  # Check if Radicle is initialized
53  if ! rad inspect > /dev/null 2>&1; then
54    echo "🌿 No Radicle project detected. Attempting init..."
55    RAD_INIT_OUTPUT=$(rad init --name git-sigil --description "GitField Ritual Repo")
56    echo "$RAD_INIT_OUTPUT"
57  fi
58  
59  # Push to Radicle and announce
60  echo "πŸ“‘ Announcing to Radicle network..."
61  rad push --announce
62  
63  # Get project ID
64  PROJECT_ID=$(rad inspect | grep "Project ID" | awk '{print $NF}')
65  if [ -n "$PROJECT_ID" ]; then
66    echo "πŸ“œ Logging Radicle project ID to .gitfield/radicle.sigil.md"
67    mkdir -p .gitfield
68    echo "# Radicle Sigil" > .gitfield/radicle.sigil.md
69    echo "**Project ID:** \`$PROJECT_ID\`" >> .gitfield/radicle.sigil.md
70  fi
71  
72  echo "βœ… GitField resolution ritual complete."