-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclaude-sync-init
More file actions
executable file
·143 lines (125 loc) · 4.51 KB
/
claude-sync-init
File metadata and controls
executable file
·143 lines (125 loc) · 4.51 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
# Claude Code Conversation Sync - Initialize Repository
# Sets up the conversations folder, clones from remote if exists, handles encryption
set -e
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-init"
exit 0
fi
load_config "$SCRIPT_DIR"
REPO_DIR="$SCRIPT_DIR/conversations"
KEY_PATH="$HOME/.claude-git-crypt.key"
echo "=== Claude Code Conversation Sync - Initialize ==="
echo ""
# Check if already initialized
if [ -d "$REPO_DIR/.git" ]; then
echo "Conversations repository already initialized at: $REPO_DIR"
echo ""
# Check encryption status
if [ -d "$REPO_DIR/.git/git-crypt" ]; then
cd "$REPO_DIR"
if git-crypt status &>/dev/null 2>&1; then
# Check if any files are encrypted but not decrypted
if git-crypt status 2>/dev/null | grep -q "not decrypted"; then
echo "Repository is encrypted but LOCKED."
echo ""
if [ -f "$KEY_PATH" ]; then
read -p "Unlock with existing key at $KEY_PATH? (yes/no): " UNLOCK
if [ "$UNLOCK" = "yes" ]; then
git-crypt unlock "$KEY_PATH" && echo "Unlocked successfully!" || echo "Failed to unlock."
fi
else
echo "To unlock, run: claude-restore-encryption-key"
fi
else
echo "Repository is encrypted and unlocked."
fi
fi
cd "$ORIGINAL_DIR"
fi
exit 0
fi
# Validate we have a remote configured
if [ -z "$CLAUDE_SYNC_REMOTE" ]; then
echo "Error: CLAUDE_SYNC_REMOTE not configured."
echo ""
echo "Set it by:"
echo " 1. Running: claude-config"
echo " 2. Or: export CLAUDE_SYNC_REMOTE=\"git@github.com:user/repo.git\""
echo ""
cd "$ORIGINAL_DIR"
exit 1
fi
echo "Remote: $CLAUDE_SYNC_REMOTE"
echo "Branch: $CLAUDE_SYNC_BRANCH"
echo ""
# Try to clone from remote
echo "Checking remote repository..."
if git ls-remote "$CLAUDE_SYNC_REMOTE" &>/dev/null; then
echo "Remote repository found. Cloning..."
if git clone "$CLAUDE_SYNC_REMOTE" "$REPO_DIR"; then
cd "$REPO_DIR"
git checkout "$CLAUDE_SYNC_BRANCH" 2>/dev/null || git checkout -b "$CLAUDE_SYNC_BRANCH"
# Check if repo uses encryption
if [ -d ".git/git-crypt" ]; then
echo ""
echo "This repository uses encryption."
echo ""
if [ -f "$KEY_PATH" ]; then
echo "Found encryption key at: $KEY_PATH"
read -p "Unlock repository now? (yes/no): " UNLOCK
if [ "$UNLOCK" = "yes" ]; then
if git-crypt unlock "$KEY_PATH"; then
echo "Repository unlocked successfully!"
else
echo ""
echo "Failed to unlock. The key may not match."
echo "Try restoring the correct key with: claude-restore-encryption-key"
cd "$ORIGINAL_DIR"
exit 1
fi
else
echo ""
echo "Repository cloned but still locked."
echo "Unlock later with: cd $REPO_DIR && git-crypt unlock $KEY_PATH"
fi
else
echo "No encryption key found at: $KEY_PATH"
echo ""
echo "Repository cloned but locked."
echo "To unlock: run 'claude-restore-encryption-key'"
fi
fi
echo ""
echo "Repository initialized successfully!"
cd "$ORIGINAL_DIR"
else
echo "Failed to clone repository."
cd "$ORIGINAL_DIR"
exit 1
fi
else
# Remote doesn't exist or is empty - initialize fresh
echo "Remote repository is empty or doesn't exist. Initializing fresh..."
mkdir -p "$REPO_DIR"
cd "$REPO_DIR"
git init
git branch -M "$CLAUDE_SYNC_BRANCH"
git remote add origin "$CLAUDE_SYNC_REMOTE"
# Create initial structure
mkdir -p projects file-history todos
echo ""
echo "Fresh repository initialized."
echo ""
echo "Next steps:"
echo " 1. (Optional) Enable encryption: claude-enable-encryption"
echo " 2. Sync your conversations: claude-sync-push"
fi
echo ""
echo "Initialization complete!"
cd "$ORIGINAL_DIR"