Add Git auto-sync for multi-device vault syncing
This commit is contained in:
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
# Git Auto-Sync: Watch for changes and auto-commit
|
||||
# Run this in the background to auto-commit changes to vault
|
||||
|
||||
VAULT_PATH="${VAULT_PATH:-.}"
|
||||
COMMIT_AUTHOR="${COMMIT_AUTHOR:-Bumblebee AI}"
|
||||
COMMIT_EMAIL="${COMMIT_EMAIL:-bumblebee@clawd.local}"
|
||||
POLL_INTERVAL="${POLL_INTERVAL:-30}" # Check every 30 seconds
|
||||
|
||||
cd "$VAULT_PATH" || exit 1
|
||||
|
||||
# Configure git user for commits
|
||||
git config user.name "$COMMIT_AUTHOR" 2>/dev/null || true
|
||||
git config user.email "$COMMIT_EMAIL" 2>/dev/null || true
|
||||
|
||||
# Enable auto-stash for merge conflicts
|
||||
git config rebase.autoStash true 2>/dev/null || true
|
||||
|
||||
echo "🔄 Git Auto-Sync started"
|
||||
echo "Vault: $VAULT_PATH"
|
||||
echo "Poll interval: ${POLL_INTERVAL}s"
|
||||
echo ""
|
||||
|
||||
# Keep track of last commit hash to avoid duplicate commits
|
||||
LAST_COMMIT=""
|
||||
|
||||
while true; do
|
||||
sleep "$POLL_INTERVAL"
|
||||
|
||||
# Check for changes
|
||||
if ! git diff-index --quiet HEAD --; then
|
||||
# There are unstaged changes
|
||||
CHANGES=$(git status --short)
|
||||
|
||||
if [ -n "$CHANGES" ]; then
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Changes detected:"
|
||||
echo "$CHANGES" | sed 's/^/ /'
|
||||
|
||||
# Stage all changes
|
||||
git add -A
|
||||
|
||||
# Create commit message with file count
|
||||
FILE_COUNT=$(echo "$CHANGES" | wc -l)
|
||||
COMMIT_MSG="Auto-sync: $FILE_COUNT files updated"
|
||||
|
||||
# Commit
|
||||
if git commit -m "$COMMIT_MSG" --no-verify 2>/dev/null; then
|
||||
echo " ✓ Committed"
|
||||
LAST_COMMIT=$(git rev-parse HEAD)
|
||||
|
||||
# Try to push (optional, if remote is configured)
|
||||
if git remote -v | grep -q .; then
|
||||
if git push -q 2>/dev/null; then
|
||||
echo " ✓ Pushed to remote"
|
||||
else
|
||||
echo " ⚠ Push failed (repo might be local-only)"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user