Skip to content

Commit ed71a85

Browse files
authored
Merge branch 'main' into copilot/fix-35a174dd-35f4-4743-b760-efa078aa9720
2 parents 1f7edd0 + 2a2079f commit ed71a85

File tree

1 file changed

+209
-0
lines changed

1 file changed

+209
-0
lines changed

.cursor/rules/sync-prs.mdc

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
---
2+
description: Sync all open pull requests with origin/main to keep them up-to-date
3+
---
4+
5+
# Sync Open PRs with origin/main
6+
7+
This rule provides a systematic approach to keeping all open pull requests synchronized with the main branch.
8+
9+
## Why Sync PRs?
10+
11+
- Prevents merge conflicts from accumulating
12+
- Ensures PRs are tested against the latest codebase
13+
- Makes reviews easier by reducing the delta between PR and main
14+
- Identifies integration issues early
15+
16+
## Prerequisites
17+
18+
1. Ensure local main is up-to-date:
19+
```bash
20+
git checkout main
21+
git pull origin main
22+
```
23+
24+
2. Fetch all remote branches:
25+
```bash
26+
git fetch origin
27+
```
28+
29+
## Process to Sync All Open PRs
30+
31+
### Step 1: Get List of Open PRs
32+
33+
Use GitHub API to list open PRs:
34+
```bash
35+
# Get current origin/main SHA
36+
git rev-parse origin/main
37+
38+
# List open PRs (requires gh CLI or use GitHub API tools)
39+
# This will show PR numbers, branches, and base commit
40+
```
41+
42+
### Step 2: Update Each PR Branch
43+
44+
For each open PR branch:
45+
46+
```bash
47+
# Checkout the PR branch
48+
git checkout <pr-branch-name>
49+
50+
# Merge origin/main
51+
git merge origin/main --no-edit
52+
53+
# If successful, push
54+
git push origin <pr-branch-name>
55+
```
56+
57+
### Step 3: Handle Merge Conflicts
58+
59+
When conflicts occur:
60+
61+
1. **Identify conflicting files**:
62+
```bash
63+
git status
64+
```
65+
66+
2. **Resolve conflicts manually**:
67+
- Read both versions carefully
68+
- Understand the intent of each change
69+
- Combine changes intelligently (don't just pick one side)
70+
- Remove conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`)
71+
72+
3. **Key principles for conflict resolution**:
73+
- Preserve new functionality from main
74+
- Keep PR-specific changes
75+
- Ensure constants/config changes are consistent
76+
- Test that the resolution compiles
77+
78+
4. **Complete the merge**:
79+
```bash
80+
git add <resolved-files>
81+
git commit --no-edit
82+
git push origin <pr-branch-name>
83+
```
84+
85+
## Common Conflict Scenarios
86+
87+
### Configuration Constants
88+
89+
When both main and PR modify constants (e.g., `DEFAULT_MODEL`):
90+
- Use the value from main for default behavior
91+
- Keep PR-specific additions (e.g., new constants like `DEFAULT_TEMPERATURE`)
92+
- Ensure visibility (pub vs non-pub) is consistent with usage
93+
94+
Example resolution:
95+
```rust
96+
// Keep main's default value
97+
pub const DEFAULT_MODEL: &str = "gpt-4.1";
98+
// Keep PR's new constant
99+
pub const DEFAULT_TEMPERATURE: f64 = 0.7;
100+
```
101+
102+
### Struct Field Changes
103+
104+
When both branches modify a struct:
105+
- Include all fields from both versions
106+
- Ensure derives are compatible (e.g., `Eq` only if all fields implement it)
107+
- Update corresponding methods to handle all fields
108+
109+
### Import Conflicts
110+
111+
When both branches add imports:
112+
- Keep all necessary imports
113+
- Follow Rust import conventions: std → external → internal
114+
- Remove duplicates
115+
- Alphabetize within groups
116+
117+
## Automation Script Template
118+
119+
```bash
120+
#!/bin/bash
121+
# sync-all-prs.sh - Sync all open PRs with origin/main
122+
123+
set -e
124+
125+
# Fetch latest
126+
git fetch origin
127+
128+
# Get main SHA
129+
MAIN_SHA=$(git rev-parse origin/main)
130+
echo "Syncing PRs to main: $MAIN_SHA"
131+
132+
# List of PR branches (populate from GitHub API)
133+
PR_BRANCHES=(
134+
"copilot/fix-branch-1"
135+
"copilot/fix-branch-2"
136+
# ... add more branches
137+
)
138+
139+
for branch in "${PR_BRANCHES[@]}"; do
140+
echo "=== Syncing $branch ==="
141+
142+
# Checkout and merge
143+
git checkout "$branch" || git checkout -b "$branch" "origin/$branch"
144+
145+
if git merge origin/main --no-edit; then
146+
echo "✓ Merged successfully"
147+
git push origin "$branch"
148+
else
149+
echo "✗ Merge conflict - manual resolution needed"
150+
echo " Conflicting files:"
151+
git status --short | grep "^UU"
152+
echo " Resolve conflicts then run:"
153+
echo " git add <files> && git commit --no-edit && git push origin $branch"
154+
exit 1
155+
fi
156+
done
157+
158+
# Return to main
159+
git checkout main
160+
echo "All PRs synced!"
161+
```
162+
163+
## Best Practices
164+
165+
1. **Sync regularly**: Update PRs weekly or after significant main branch changes
166+
2. **Test after sync**: Run tests to ensure the merge didn't break anything
167+
3. **Review conflicts carefully**: Don't blindly accept one side
168+
4. **Document complex resolutions**: Add comments explaining non-obvious merge decisions
169+
5. **Clean up**: Return to main branch when done
170+
6. **Verify builds**: Run `cargo check` or `cargo build` after resolving conflicts
171+
172+
## Troubleshooting
173+
174+
### "Your local changes would be overwritten"
175+
```bash
176+
# Stash or commit your changes first
177+
git stash
178+
# or
179+
git commit -am "WIP: save current work"
180+
```
181+
182+
### "Branch is up to date" but GitHub shows behind
183+
```bash
184+
# Force fetch to update remote tracking
185+
git fetch origin --force
186+
```
187+
188+
### Accidentally pushed broken code
189+
```bash
190+
# Fix the issue, then amend and force push (be careful!)
191+
git commit --amend --no-edit
192+
git push origin <branch> --force-with-lease
193+
```
194+
195+
## Related Files
196+
197+
- [src/config.rs](mdc:src/config.rs) - Often contains constants that conflict
198+
- [src/model.rs](mdc:src/model.rs) - Model definitions that may conflict
199+
- [Cargo.toml](mdc:Cargo.toml) - Dependency version conflicts
200+
201+
## Verification Checklist
202+
203+
After syncing each PR:
204+
- [ ] No merge conflict markers remain in code
205+
- [ ] Code compiles: `cargo check`
206+
- [ ] No new clippy warnings: `cargo clippy`
207+
- [ ] Tests pass: `cargo test`
208+
- [ ] PR branch is pushed to origin
209+
- [ ] GitHub shows PR is up-to-date with base branch

0 commit comments

Comments
 (0)