-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclaude-sync-pull
More file actions
executable file
·117 lines (94 loc) · 3.17 KB
/
claude-sync-pull
File metadata and controls
executable file
·117 lines (94 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
# Claude Code Conversation Sync - Pull
# Syncs conversations from remote repo to ~/.claude
set -e
# Save original directory to return to it at the end
ORIGINAL_DIR="$(pwd)"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Load configuration
source "$SCRIPT_DIR/lib-claude-sync.sh"
# Handle --version flag
if [ "$1" = "--version" ] || [ "$1" = "-v" ]; then
show_version "$SCRIPT_DIR" "claude-sync-pull"
exit 0
fi
load_config "$SCRIPT_DIR"
CLAUDE_DIR="$CLAUDE_DATA_DIR"
REPO_DIR="$SCRIPT_DIR/conversations"
echo "=== Claude Code Conversation Sync - Pull ==="
echo "Syncing from: $REPO_DIR"
echo "Syncing to: $CLAUDE_DIR"
echo ""
log_verbose "Using branch: $CLAUDE_SYNC_BRANCH"
# Check if repo is initialized
if [ ! -d "$REPO_DIR/.git" ]; then
echo "Error: Conversations repository not initialized."
echo ""
echo "Run 'claude-sync-init' first to set up the repository."
cd "$ORIGINAL_DIR"
exit 1
fi
cd "$REPO_DIR"
# Check if encrypted repo is locked
if [ -d ".git/git-crypt" ]; then
if git-crypt status 2>/dev/null | grep -q "not decrypted"; then
echo "Error: Repository is encrypted but locked."
echo ""
echo "Unlock first with: claude-restore-encryption-key"
echo "Or manually: cd $REPO_DIR && git-crypt unlock ~/.claude-git-crypt.key"
cd "$ORIGINAL_DIR"
exit 1
fi
fi
# Pull from remote
if git remote | grep -q origin 2>/dev/null; then
echo "Pulling from remote..."
git pull origin "$CLAUDE_SYNC_BRANCH" 2>/dev/null || {
echo "Warning: Could not pull. Using local copy."
}
else
echo "No git remote configured. Using local copy."
fi
cd "$SCRIPT_DIR"
# Create Claude directory if it doesn't exist
mkdir -p "$CLAUDE_DIR"
# Sync with rsync (preserves newer files)
echo ""
echo "Syncing conversations to $CLAUDE_DIR..."
# Sync projects
if [ -d "$REPO_DIR/projects" ]; then
echo "Syncing project conversations..."
rsync -av --update "$REPO_DIR/projects/" "$CLAUDE_DIR/projects/"
fi
# Sync file-history
if [ -d "$REPO_DIR/file-history" ]; then
echo "Syncing file history..."
rsync -av --update "$REPO_DIR/file-history/" "$CLAUDE_DIR/file-history/"
fi
# Sync todos
if [ -d "$REPO_DIR/todos" ]; then
echo "Syncing todos..."
rsync -av --update "$REPO_DIR/todos/" "$CLAUDE_DIR/todos/"
fi
# Sync global history (merge, don't overwrite)
if [ -f "$REPO_DIR/history.jsonl" ]; then
echo "Syncing global history..."
if [ -f "$CLAUDE_DIR/history.jsonl" ]; then
# Merge history files (keep both, sort by timestamp)
cat "$CLAUDE_DIR/history.jsonl" "$REPO_DIR/history.jsonl" | \
sort -u > "$CLAUDE_DIR/history.jsonl.tmp"
mv "$CLAUDE_DIR/history.jsonl.tmp" "$CLAUDE_DIR/history.jsonl"
else
cp "$REPO_DIR/history.jsonl" "$CLAUDE_DIR/history.jsonl"
fi
fi
# Set correct permissions
chmod -R u+rwX,go-rwx "$CLAUDE_DIR/projects" 2>/dev/null || true
chmod -R u+rwX,go-rwx "$CLAUDE_DIR/file-history" 2>/dev/null || true
chmod -R u+rwX,go-rwx "$CLAUDE_DIR/todos" 2>/dev/null || true
echo ""
echo "Sync complete!"
echo ""
echo "Note: Restart Claude Code to see the synced conversations."
# Return to original directory
cd "$ORIGINAL_DIR"