Sync 2026-04-13 22:51

This commit is contained in:
2026-04-13 22:51:52 +00:00
parent 6f3ba33e02
commit 209487e393

28
sync.sh
View File

@@ -1,19 +1,15 @@
#!/bin/bash
# Hermes Sync Script - 真正的双向合并同步
set -e
SYNC_DIR="${SYNC_DIR:-$HOME/.hermes-sync}"
HERMES_HOME="${HERMES_HOME:-$HOME/.hermes}"
SYNC_DIR="$HOME/.hermes-sync"
HERMES_HOME="$HOME/.hermes"
cd "$SYNC_DIR"
git config pull.rebase false
echo "[$(date '+%H:%M:%S')] Starting sync..."
echo "[$(date '+%H:%M:%S')] Syncing..."
# Stage local changes
cp "$HERMES_HOME/memories/MEMORY.md" "$SYNC_DIR/memories/MEMORY.md" 2>/dev/null || true
if [ -d "$HERMES_HOME/skills" ]; then
mkdir -p "$SYNC_DIR/memories" "$SYNC_DIR/skills"
mkdir -p "$SYNC_DIR/skills"
rsync -a --delete "$HERMES_HOME/skills/" "$SYNC_DIR/skills/" 2>/dev/null || true
fi
git add -A
@@ -25,17 +21,13 @@ fi
# Fetch and merge remote
git fetch origin main
if git rev-parse HEAD >/dev/null 2>&1 && \
git rev-parse origin/main >/dev/null 2>&1 && \
! git merge-base --is-ancestor HEAD origin/main 2>/dev/null; then
echo "[$(date '+%H:%M:%S')] Remote has changes, merging..."
echo "Merging remote..."
if [ "$HAS_LOCAL" = true ]; then
git stash push -m "local $(date)" 2>/dev/null || true
if ! git merge origin/main --no-edit 2>/dev/null; then
# Conflict: keep ours for all
git checkout --ours sync.sh 2>/dev/null || true
git checkout --ours memories/MEMORY.md 2>/dev/null || true
git add -A
git commit -m "Auto-resolve $(date)" 2>/dev/null || true
@@ -56,19 +48,17 @@ fi
if [ "$HAS_LOCAL" = true ]; then
git commit -m "Sync $(date '+%Y-%m-%d %H:%M')" 2>/dev/null || true
if ! git push origin main 2>&1; then
echo "[$(date '+%H:%M:%S')] Push rejected, pulling..."
echo "Push rejected, pulling..."
git pull origin main --no-edit 2>/dev/null || true
git push origin main 2>&1 || echo "[$(date '+%H:%M:%S')] Push failed"
git push origin main 2>&1 || echo "Push failed"
fi
else
echo "[$(date '+%H:%M:%S')] No local changes"
fi
# Apply merged result to hermes home
# Apply to hermes
cp "$SYNC_DIR/memories/MEMORY.md" "$HERMES_HOME/memories/MEMORY.md" 2>/dev/null || true
if [ -d "$SYNC_DIR/skills" ]; then
rsync -a --ignore-existing "$SYNC_DIR/skills/" "$HERMES_HOME/skills/" 2>/dev/null || \
cp -rn "$SYNC_DIR/skills/"* "$HERMES_HOME/skills/" 2>/dev/null || true
fi
echo "[$(date '+%H:%M:%S')] Sync complete"
echo "Done"