-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclaude-sync-push
More file actions
executable file
·126 lines (102 loc) · 3.23 KB
/
claude-sync-push
File metadata and controls
executable file
·126 lines (102 loc) · 3.23 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
#!/bin/bash
# Claude Code Conversation Sync - Push
# Syncs conversations from ~/.claude to repo and pushes to remote
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-push"
exit 0
fi
load_config "$SCRIPT_DIR"
CLAUDE_DIR="$CLAUDE_DATA_DIR"
REPO_DIR="$SCRIPT_DIR/conversations"
echo "=== Claude Code Conversation Sync - Push ==="
echo "Syncing from: $CLAUDE_DIR"
echo "Syncing to: $REPO_DIR"
echo ""
# Validate configuration
if ! validate_config; then
cd "$ORIGINAL_DIR"
exit 1
fi
# 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
# Check for encrypted but not decrypted files
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 latest from remote first
if git remote | grep -q origin 2>/dev/null; then
echo "Pulling latest from remote..."
git pull origin "$CLAUDE_SYNC_BRANCH" 2>/dev/null || {
echo "Note: Could not pull. Continuing with local merge..."
}
echo ""
fi
# Create directory structure
mkdir -p "$REPO_DIR/projects"
mkdir -p "$REPO_DIR/file-history"
mkdir -p "$REPO_DIR/todos"
# Sync projects (conversations) - MERGE, don't delete
echo "Merging local conversations into repo..."
rsync -av --update "$CLAUDE_DIR/projects/" "$REPO_DIR/projects/"
# Sync file-history - MERGE, don't delete
echo "Merging file history..."
rsync -av --update "$CLAUDE_DIR/file-history/" "$REPO_DIR/file-history/"
# Sync todos - MERGE, don't delete
echo "Merging todos..."
rsync -av --update "$CLAUDE_DIR/todos/" "$REPO_DIR/todos/"
# Sync global history
echo "Syncing global history..."
if [ -f "$CLAUDE_DIR/history.jsonl" ]; then
cp "$CLAUDE_DIR/history.jsonl" "$REPO_DIR/history.jsonl"
fi
# Check if there are changes
if [ -z "$(git status --porcelain)" ]; then
echo ""
echo "No changes to sync."
cd "$ORIGINAL_DIR"
exit 0
fi
echo ""
echo "Changes detected. Committing..."
git add .
# Use configured commit message template
COMMIT_MSG="${CLAUDE_SYNC_COMMIT_MSG}"
COMMIT_MSG="${COMMIT_MSG//\{date\}/$(date '+%Y-%m-%d')}"
COMMIT_MSG="${COMMIT_MSG//\{time\}/$(date '+%H:%M:%S')}"
COMMIT_MSG="${COMMIT_MSG//\{hostname\}/$(hostname)}"
git commit -m "$COMMIT_MSG"
# Push to remote
if git remote | grep -q origin; then
echo "Pushing to remote..."
git push origin "$CLAUDE_SYNC_BRANCH" || {
echo "Warning: Could not push."
echo " You may need to pull first or resolve conflicts."
}
else
echo ""
echo "No git remote configured. Run 'claude-config' to set it up."
fi
echo ""
echo "Sync complete!"
cd "$ORIGINAL_DIR"