Skip to content

Commit 84601a6

Browse files
author
Gabi
committed
feat: recreate sync script after repository cleanup
1 parent 6b30579 commit 84601a6

File tree

1 file changed

+195
-0
lines changed

1 file changed

+195
-0
lines changed

scripts/sync-upstream.sh

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
#!/bin/bash
2+
3+
# Postiz App - Upstream Sync Script
4+
# This script helps manage syncing between upstream, public fork, and private repository
5+
6+
set -e
7+
8+
echo "🔄 Starting upstream sync process..."
9+
10+
# Colors for output
11+
GREEN='\033[0;32m'
12+
BLUE='\033[0;34m'
13+
YELLOW='\033[1;33m'
14+
RED='\033[0;31m'
15+
NC='\033[0m' # No Color
16+
17+
# Function to print colored output
18+
print_status() {
19+
echo -e "${BLUE}[INFO]${NC} $1"
20+
}
21+
22+
print_success() {
23+
echo -e "${GREEN}[SUCCESS]${NC} $1"
24+
}
25+
26+
print_warning() {
27+
echo -e "${YELLOW}[WARNING]${NC} $1"
28+
}
29+
30+
print_error() {
31+
echo -e "${RED}[ERROR]${NC} $1"
32+
}
33+
34+
# Check if we're in a git repository
35+
if ! git rev-parse --git-dir > /dev/null 2>&1; then
36+
print_error "Not in a git repository!"
37+
exit 1
38+
fi
39+
40+
# Check if all remotes exist
41+
check_remotes() {
42+
print_status "Checking remotes..."
43+
44+
if ! git remote | grep -q "^upstream$"; then
45+
print_error "upstream remote not found. Please add it with:"
46+
echo "git remote add upstream https://github.com/gitroomhq/postiz-app.git"
47+
exit 1
48+
fi
49+
50+
if ! git remote | grep -q "^origin$"; then
51+
print_error "origin remote not found."
52+
exit 1
53+
fi
54+
55+
if ! git remote | grep -q "^private$"; then
56+
print_error "private remote not found. Please add it with:"
57+
echo "git remote add private https://github.com/gabelul/postiz-app-private.git"
58+
exit 1
59+
fi
60+
61+
print_success "All remotes configured correctly"
62+
}
63+
64+
# Fetch all remotes
65+
fetch_all() {
66+
print_status "Fetching from all remotes..."
67+
git fetch upstream
68+
git fetch origin
69+
git fetch private
70+
print_success "Fetched all remotes"
71+
}
72+
73+
# Sync public fork with upstream
74+
sync_public_fork() {
75+
print_status "Syncing public fork (main) with upstream..."
76+
77+
# Switch to main branch
78+
git checkout main
79+
80+
# Check if there are uncommitted changes
81+
if ! git diff --quiet || ! git diff --cached --quiet; then
82+
print_warning "Uncommitted changes detected. Please commit or stash them first."
83+
return 1
84+
fi
85+
86+
# Merge upstream changes
87+
git merge upstream/main
88+
89+
# Push to public fork
90+
git push origin main
91+
92+
print_success "Public fork synced with upstream"
93+
}
94+
95+
# Show differences between upstream and private
96+
show_diff() {
97+
print_status "Showing differences between upstream/main and private-main..."
98+
99+
git checkout private-main
100+
echo -e "${BLUE}Files modified in private version:${NC}"
101+
git diff --name-only upstream/main..private-main
102+
103+
echo -e "${BLUE}Commit differences:${NC}"
104+
git log --oneline upstream/main..private-main
105+
}
106+
107+
# Merge upstream changes to private branch
108+
merge_to_private() {
109+
print_status "Merging upstream changes to private-main..."
110+
111+
git checkout private-main
112+
113+
# Check if there are uncommitted changes
114+
if ! git diff --quiet || ! git diff --cached --quiet; then
115+
print_warning "Uncommitted changes detected. Please commit or stash them first."
116+
return 1
117+
fi
118+
119+
# Create a backup branch before merging
120+
backup_branch="private-main-backup-$(date +%Y%m%d-%H%M%S)"
121+
git branch $backup_branch
122+
print_status "Created backup branch: $backup_branch"
123+
124+
# Merge upstream changes
125+
if git merge upstream/main; then
126+
print_success "Successfully merged upstream changes to private-main"
127+
128+
# Push to private repository
129+
git push private private-main
130+
print_success "Pushed updated private-main to private repository"
131+
132+
# Clean up backup branch
133+
git branch -d $backup_branch
134+
print_status "Cleaned up backup branch"
135+
else
136+
print_error "Merge conflicts detected. Please resolve them manually."
137+
print_status "Backup branch created: $backup_branch"
138+
echo "After resolving conflicts, run: git push private private-main"
139+
return 1
140+
fi
141+
}
142+
143+
# Main function to handle command line arguments
144+
main() {
145+
case "${1:-}" in
146+
"check")
147+
check_remotes
148+
;;
149+
"fetch")
150+
check_remotes
151+
fetch_all
152+
;;
153+
"sync-public")
154+
check_remotes
155+
fetch_all
156+
sync_public_fork
157+
;;
158+
"show-diff")
159+
check_remotes
160+
fetch_all
161+
show_diff
162+
;;
163+
"merge-private")
164+
check_remotes
165+
fetch_all
166+
merge_to_private
167+
;;
168+
"full-sync")
169+
check_remotes
170+
fetch_all
171+
sync_public_fork
172+
show_diff
173+
echo -e "${YELLOW}Review the differences above. Run with 'merge-private' to merge upstream changes to private branch.${NC}"
174+
;;
175+
*)
176+
echo "Usage: $0 {check|fetch|sync-public|show-diff|merge-private|full-sync}"
177+
echo ""
178+
echo "Commands:"
179+
echo " check - Verify all remotes are configured"
180+
echo " fetch - Fetch from all remotes"
181+
echo " sync-public - Sync public fork (main) with upstream"
182+
echo " show-diff - Show differences between upstream and private"
183+
echo " merge-private - Merge upstream changes to private-main"
184+
echo " full-sync - Run sync-public and show-diff"
185+
echo ""
186+
echo "Typical workflow:"
187+
echo " 1. $0 full-sync"
188+
echo " 2. Review differences"
189+
echo " 3. $0 merge-private (if you want to merge upstream changes)"
190+
exit 1
191+
;;
192+
esac
193+
}
194+
195+
main "$@"

0 commit comments

Comments
 (0)