forked from ArcadeData/arcadedb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync-upstream.sh
More file actions
executable file
·412 lines (355 loc) · 12.9 KB
/
Copy pathsync-upstream.sh
File metadata and controls
executable file
·412 lines (355 loc) · 12.9 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#!/bin/bash
# Script to sync upstream changes while preserving fork-specific customizations
#
# This fork maintains two protected path categories during sync:
# 1. fork-owned files that should always keep the fork's version
# 2. fork-excluded files that should stay absent from the fork even if
# upstream contains them
# Everything else, including bindings/python/, is merged normally from
# upstream-main into main.
#
# Usage: ./sync-upstream.sh [--help|--status|--dry-run]
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
FORK_OWNED_PATHS=(
"README.md"
)
FORK_EXCLUDED_PATHS=(
"CLAUDE.md"
".github/workflows/benchmark-tests.yml"
".github/workflows/claude-code-review.yml"
".github/workflows/claude.yml"
".github/workflows/ha-resilience-tests.yml"
".github/workflows/load-tests.yml"
".github/workflows/license-compliance.yml"
".github/workflows/meterian.yml"
".github/workflows/mvn-deploy.yml"
".github/workflows/mvn-release.yml"
".github/workflows/mvn-test.yml"
".github/workflows/studio-security-audit.yml"
)
PROTECTED_SOURCE_REV=""
SYNC_TARGET_REF="upstream/main"
resolve_sync_target() {
local requested_ref="$1"
if [ -z "$requested_ref" ]; then
SYNC_TARGET_REF="upstream/main"
return 0
fi
if ! git rev-parse --verify --quiet "$requested_ref" >/dev/null; then
echo -e "${RED}❌ Target revision not found: $requested_ref${NC}"
exit 1
fi
if ! git merge-base --is-ancestor "$requested_ref" upstream/main; then
echo -e "${RED}❌ Target revision is not an ancestor of upstream/main: $requested_ref${NC}"
exit 1
fi
SYNC_TARGET_REF=$(git rev-parse --short=12 "$requested_ref")
}
try_auto_resolve() {
local conflicts resolved path handled
conflicts=$(git diff --name-only --diff-filter=U)
if [ -z "$conflicts" ]; then
return 1
fi
resolved=0
for path in $conflicts; do
handled=0
if restore_path_to_fork_state "$path"; then
resolved=1
handled=1
fi
if [ "$handled" -eq 1 ]; then
continue
fi
done
if [ "$resolved" -eq 1 ]; then
return 0
fi
return 1
}
capture_protected_source_rev() {
PROTECTED_SOURCE_REV=$(git rev-parse HEAD)
}
restore_path_to_fork_state() {
local path="$1"
local protected_path
for protected_path in "${FORK_OWNED_PATHS[@]}" "${FORK_EXCLUDED_PATHS[@]}"; do
if [[ "$path" == "$protected_path" ]]; then
if git cat-file -e "$PROTECTED_SOURCE_REV:$path" >/dev/null 2>&1; then
git restore --source="$PROTECTED_SOURCE_REV" --staged --worktree -- "$path"
git add "$path"
else
git rm -r --cached --ignore-unmatch --quiet -- "$path" >/dev/null 2>&1 || true
rm -rf -- "$path"
fi
return 0
fi
done
return 1
}
restore_protected_paths() {
local path tracked_entry
for path in "${FORK_OWNED_PATHS[@]}" "${FORK_EXCLUDED_PATHS[@]}"; do
while IFS= read -r tracked_entry; do
[ -n "$tracked_entry" ] || continue
if ! git cat-file -e "$PROTECTED_SOURCE_REV:$tracked_entry" >/dev/null 2>&1; then
git rm -r --cached --ignore-unmatch --quiet -- "$tracked_entry" >/dev/null 2>&1 || true
rm -rf -- "$tracked_entry"
fi
done < <(git ls-files -- "$path")
if git cat-file -e "$PROTECTED_SOURCE_REV:$path" >/dev/null 2>&1; then
git restore --source="$PROTECTED_SOURCE_REV" --staged --worktree -- "$path"
fi
done
}
# Show help
show_help() {
cat << EOF
${BLUE}🔄 Upstream Sync Script${NC}
Syncs this fork with upstream ArcadeData/arcadedb while keeping:
- upstream-main: clean mirror of upstream/main
- main: fork changes merged with upstream-main
${YELLOW}Usage:${NC}
./sync-upstream.sh Sync with upstream (interactive)
./sync-upstream.sh --until <commit>
Sync only up to a specific upstream commit
./sync-upstream.sh --dry-run Show what would be synced (no changes)
./sync-upstream.sh --status Check sync status only
./sync-upstream.sh --help Show this help
${YELLOW}Fork-Owned Files (restored after merge):${NC}
• README.md
${YELLOW}Fork-Excluded Files (kept out of the fork):${NC}
• CLAUDE.md
• .github/workflows/benchmark-tests.yml
• .github/workflows/claude-code-review.yml
• .github/workflows/claude.yml
• .github/workflows/ha-resilience-tests.yml
• .github/workflows/load-tests.yml
• .github/workflows/license-compliance.yml
• .github/workflows/meterian.yml
• .github/workflows/mvn-deploy.yml
• .github/workflows/mvn-release.yml
• .github/workflows/mvn-test.yml
• .github/workflows/studio-security-audit.yml
${YELLOW}Normal Merge Paths:${NC}
• .github/workflows/release-python-packages.yml
• .github/workflows/deploy-python-docs.yml
• .github/workflows/test-python-bindings.yml
• .github/workflows/test-python-examples.yml
• bindings/python/ - Merges normally from upstream-main into main
${YELLOW}After Sync:${NC}
1. Test: cd bindings/python && ./scripts/build.sh linux/amd64 && pytest tests/
(or on Windows: ./scripts/build.sh windows/amd64; on macOS: ./scripts/build.sh darwin/arm64)
2. Push: git push origin main
${YELLOW}Troubleshooting:${NC}
Abort merge: git merge --abort
View changes: git log main..upstream-main --oneline
Check divergence: git log upstream-main..main --oneline
${YELLOW}Examples:${NC}
./sync-upstream.sh --until 96a306bed
./sync-upstream.sh --dry-run --until upstream/main~10
${CYAN}Learn more: https://github.com/humemai/arcadedb-embedded-python${NC}
EOF
exit 0
}
# Check sync status
check_status() {
echo -e "${BLUE}📊 Fork Sync Status${NC}"
echo ""
git fetch upstream --no-tags --quiet
resolve_sync_target "$STATUS_TARGET"
if ! git show-ref --verify --quiet refs/heads/upstream-main; then
echo -e "${YELLOW}⚠️ upstream-main branch not found. Run './sync-upstream.sh' to create it.${NC}"
exit 0
fi
AHEAD=$(git rev-list --count upstream-main..main 2>/dev/null || echo 0)
BEHIND=$(git rev-list --count main.."$SYNC_TARGET_REF" 2>/dev/null || echo 0)
MIRROR_PENDING=$(git rev-list --count upstream-main.."$SYNC_TARGET_REF" 2>/dev/null || echo 0)
echo -e "${YELLOW}Branch:${NC} main (fork)"
echo -e "${YELLOW}Upstream mirror:${NC} upstream-main"
echo -e "${YELLOW}Remote:${NC} origin (humemai/arcadedb-embedded-python)"
echo -e "${YELLOW}Upstream:${NC} upstream (ArcadeData/arcadedb)"
echo -e "${YELLOW}Sync target:${NC} $SYNC_TARGET_REF"
echo ""
if [ "$MIRROR_PENDING" -eq 0 ]; then
echo -e "${GREEN}✅ upstream-main already matches $SYNC_TARGET_REF${NC}"
else
echo -e "${YELLOW}⚠️ upstream-main is behind $SYNC_TARGET_REF by $MIRROR_PENDING commit(s)${NC}"
fi
if [ "$BEHIND" -eq 0 ]; then
echo -e "${GREEN}✅ main already contains $SYNC_TARGET_REF${NC}"
else
echo -e "${YELLOW}⚠️ main is behind $SYNC_TARGET_REF by $BEHIND commit(s)${NC}"
echo ""
echo -e "${CYAN}Recent upstream changes:${NC}"
git log main.."$SYNC_TARGET_REF" --oneline --max-count=5
echo ""
echo -e "${BLUE}💡 Run './sync-upstream.sh' to sync${NC}"
fi
if [ "$AHEAD" -gt 0 ]; then
echo -e "${CYAN}📝 Fork-specific commits: $AHEAD${NC}"
fi
exit 0
}
# Parse arguments
DRY_RUN=false
STATUS_ONLY=false
STATUS_TARGET=""
REQUESTED_TARGET=""
while [ $# -gt 0 ]; do
case "$1" in
--help|-h)
show_help
;;
--status|-s)
STATUS_ONLY=true
;;
--dry-run|-n)
DRY_RUN=true
;;
--until)
if [ $# -lt 2 ]; then
echo -e "${RED}❌ Missing revision after --until${NC}"
exit 1
fi
REQUESTED_TARGET="$2"
STATUS_TARGET="$2"
shift
;;
*)
echo -e "${RED}❌ Unknown option: $1${NC}"
echo -e "${YELLOW}💡 Use --help for usage information${NC}"
exit 1
;;
esac
shift
done
if [ "$STATUS_ONLY" = true ]; then
check_status
fi
echo -e "${BLUE}🔄 Syncing with upstream ArcadeData/arcadedb...${NC}"
echo ""
# 1. Fetch latest upstream changes
echo -e "${YELLOW}📥 Fetching upstream changes...${NC}"
git fetch upstream --no-tags
resolve_sync_target "$REQUESTED_TARGET"
TARGET_LABEL="$SYNC_TARGET_REF"
# 2. Check current status
echo -e "${YELLOW}📊 Checking current branch...${NC}"
CURRENT_BRANCH=$(git branch --show-current)
START_BRANCH="$CURRENT_BRANCH"
# 3. Ensure upstream-main exists
if ! git show-ref --verify --quiet refs/heads/upstream-main; then
echo -e "${YELLOW}➕ Creating upstream-main from upstream/main${NC}"
git branch upstream-main upstream/main
fi
# 4. Show what will be synced
echo ""
UPSTREAM_COMMITS=$(git rev-list --count upstream-main.."$SYNC_TARGET_REF")
PENDING_MERGE_COMMITS=$(git rev-list --count main.."$SYNC_TARGET_REF")
if [ "$UPSTREAM_COMMITS" -eq 0 ]; then
echo -e "${GREEN}✅ upstream-main already matches $TARGET_LABEL${NC}"
else
echo -e "${BLUE}📋 Changes up to $TARGET_LABEL ($UPSTREAM_COMMITS new commit(s)):${NC}"
git log upstream-main.."$SYNC_TARGET_REF" --oneline
fi
echo ""
if [ "$PENDING_MERGE_COMMITS" -eq 0 ]; then
echo -e "${GREEN}✅ main already contains $TARGET_LABEL${NC}"
else
echo -e "${BLUE}📋 Changes that will be merged into main ($PENDING_MERGE_COMMITS commit(s)):${NC}"
git log main.."$SYNC_TARGET_REF" --oneline --max-count=10
fi
# 5. Dry run mode
if [ "$DRY_RUN" = true ]; then
echo ""
echo -e "${CYAN}🔍 Dry run mode - no changes will be made${NC}"
echo -e "${GREEN}✅ Dry run complete${NC}"
exit 0
fi
# 6. Check for uncommitted changes
if ! git diff-index --quiet HEAD --; then
echo -e "${RED}❌ You have uncommitted changes${NC}"
echo -e "${YELLOW}💡 Please commit or stash your changes first${NC}"
git status --short
exit 1
fi
# 6b. Capture the exact tracked fork state for fork-protected files before merge
capture_protected_source_rev
# 7. Ask for confirmation
echo ""
read -p "$(echo -e ${YELLOW}Continue with merge? [y/N]: ${NC})" -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "${RED}❌ Sync cancelled${NC}"
exit 1
fi
# 8. Update upstream-main mirror
echo ""
echo -e "${YELLOW}🔄 Updating upstream-main...${NC}"
git checkout upstream-main
git reset --hard "$SYNC_TARGET_REF"
# 9. Merge upstream-main into main
echo -e "${YELLOW}🔄 Merging upstream-main into main...${NC}"
git checkout main
if git merge-base --is-ancestor upstream-main main; then
echo -e "${GREEN}✅ No merge needed - main already contains upstream-main${NC}"
elif git merge --no-edit upstream-main; then
echo -e "${GREEN}✅ Merge successful!${NC}"
else
while try_auto_resolve; do
if git merge --continue; then
echo -e "${GREEN}✅ Merge successful!${NC}"
break
fi
done
if [ -f .git/MERGE_HEAD ]; then
echo -e "${RED}❌ Merge failed with conflicts${NC}"
echo ""
echo -e "${YELLOW}🔧 Conflict resolution steps:${NC}"
echo -e " 1. Resolve conflicts in the listed files"
echo -e " 2. Stage resolved files: ${BLUE}git add <file>${NC}"
echo -e " 3. Continue merge: ${BLUE}git merge --continue${NC}"
echo -e " 4. Or abort: ${BLUE}git merge --abort${NC}"
echo ""
echo -e "${CYAN}Run './sync-upstream.sh --help' for more troubleshooting tips${NC}"
exit 1
fi
fi
# 9b. Restore fork-protected files exactly as they were before the merge
restore_protected_paths
# Commit fork-specific preservation changes only when needed
if ! git diff --cached --quiet; then
git commit -m "chore(sync): preserve fork custom files"
fi
# 10. Return to original branch if needed
if [ "$START_BRANCH" != "main" ] && [ "$START_BRANCH" != "upstream-main" ]; then
git checkout "$START_BRANCH" >/dev/null 2>&1 || true
fi
# 11. Show summary
echo ""
echo -e "${GREEN}🎉 Sync complete!${NC}"
echo -e "${YELLOW}Synced through:${NC} $TARGET_LABEL"
echo ""
echo -e "${BLUE}📊 Next steps (IMPORTANT):${NC}"
echo ""
echo -e " ${CYAN}1. Review changes:${NC}"
echo -e " ${YELLOW}git log --oneline -10${NC}"
echo ""
echo -e " ${CYAN}2. Test locally (REQUIRED):${NC}"
echo -e " ${YELLOW}cd bindings/python && ./scripts/build.sh linux/amd64${NC}"
echo -e " ${YELLOW}pytest tests/ -v${NC}"
echo -e " ${YELLOW}(or ./scripts/build.sh windows/amd64 on Windows; ./scripts/build.sh darwin/arm64 on macOS)${NC}"
echo ""
echo -e " ${CYAN}3. Push to your fork:${NC}"
echo -e " ${YELLOW}git push origin main${NC}"
echo ""
echo -e "${YELLOW}⚠️ Always test before pushing!${NC}"
echo ""