|
1 | | -# Restack |
2 | | - |
3 | | -Use when user asks to "restack", "resolve conflicts", "gt restack", or mentions restack conflicts. Guides through gt restack conflicts with intelligent diagnostics and resolution. (project) |
| 1 | +--- |
| 2 | +name: restack |
| 3 | +description: Use when user asks to "restack", "resolve conflicts", "gt restack", or mentions restack conflicts. Guides through gt restack conflicts with intelligent diagnostics and resolution. |
| 4 | +allowed-tools: Bash(gt restack:*), Bash(gt continue:*), Bash(git show:*), Bash(git diff:*), Bash(git log:*), Bash(git ls-tree:*), Bash(pnpm install:*), Bash(git status:*), Bash(gt log:*), Bash(rm pnpm-lock.yaml), Bash(gt add -A:*), Bash(git checkout --theirs:*), Bash(git checkout --ours:*) |
| 5 | +--- |
4 | 6 |
|
5 | 7 | <critical> |
6 | | -- ALWAYS check current state first (supports both: starting fresh or mid-conflict) |
7 | | -- If already in conflict, skip running gt restack and go straight to resolution |
8 | | -- Differentiate simple (lockfile-only) vs complex (multi-file) conflicts |
| 8 | +- Analyze embedded state below before acting |
| 9 | +- If conflict shown, skip gt restack and route immediately |
9 | 10 | - Loop until restack completes successfully |
10 | | -- Use AskUserQuestion for confirmations and choices |
| 11 | +- Use AskUserQuestion for all confirmations |
11 | 12 | </critical> |
12 | 13 |
|
13 | | -## Workflow |
| 14 | +## Current State |
14 | 15 |
|
15 | | -### 1. Detect Current State |
| 16 | +**Repository status:** |
| 17 | +!`git --no-pager -c color.ui=false status` |
16 | 18 |
|
17 | | -First, check if restack is already in progress: |
| 19 | +**Current stack:** |
| 20 | +!`gt --no-color log short --stack` |
18 | 21 |
|
19 | | -```bash |
20 | | -git status |
21 | | -``` |
| 22 | +## Workflow |
22 | 23 |
|
23 | | -**Check for**: |
24 | | -- "rebase in progress" |
25 | | -- "You are currently rebasing" |
26 | | -- "Unmerged paths" |
27 | | -- "both modified:" or other conflict indicators |
| 24 | +### 1. Analyze State |
28 | 25 |
|
29 | | -**Outcomes**: |
30 | | -- Already in conflict (user ran `gt restack` manually) → Skip to step 3 (Gather Diagnostics) |
31 | | -- Clean state → Proceed to step 2 (Run Restack) |
| 26 | +Check `git status` output above: |
| 27 | +- **"rebase in progress"** or **"Unmerged paths"** → Already in conflict, skip to step 3 |
| 28 | +- **Clean working tree** → Proceed to step 2 |
32 | 29 |
|
33 | | -### 2. Run Restack (if not already in progress) |
| 30 | +### 2. Run Restack (if clean state) |
34 | 31 |
|
35 | 32 | ```bash |
36 | 33 | gt restack |
37 | 34 | ``` |
38 | 35 |
|
39 | | -**Outcomes**: |
40 | | -- Success → Acknowledge and exit |
41 | | -- Conflicts → Proceed to step 3 |
42 | | - |
43 | | -### 3. Gather Diagnostics |
44 | | - |
45 | | -When conflicts are detected (either from step 1 or step 2), run: |
46 | | - |
47 | | -```bash |
48 | | -# Check which files are conflicted |
49 | | -git status |
50 | | - |
51 | | -# Show stack structure (where conflict occurred) |
52 | | -gt log short |
53 | | - |
54 | | -# Check for broken lockfile warning |
55 | | -pnpm install --dry-run 2>&1 | grep -i "broken\|duplicated\|ignoring" |
56 | | - |
57 | | -# For each conflicted file, show diff |
58 | | -git diff <file> |
59 | | -``` |
60 | | - |
61 | | -### 3. Explain Conflict Type |
62 | | - |
63 | | -**Simple conflict** (lockfile-only): |
64 | | -- Only `pnpm-lock.yaml` in unmerged files |
65 | | -- Explain: Lockfile is generated content, safe to regenerate |
66 | | -- Propose: `pnpm install && gt add -A && gt continue` |
67 | | - |
68 | | -**Complex conflict** (multi-file): |
69 | | -- Multiple files in unmerged files |
70 | | -- Explain each file's conflict |
71 | | -- Guide through resolution strategy |
72 | | - |
73 | | -### 4. Resolve Based on Type |
74 | | - |
75 | | -#### Simple Conflict Resolution |
76 | | - |
77 | | -Use AskUserQuestion: |
78 | | -``` |
79 | | -question: "Only pnpm-lock.yaml is conflicted. Regenerate and continue?" |
80 | | -header: "Simple Resolution" |
81 | | -options: |
82 | | - - label: "Yes, run one-liner" |
83 | | - description: "pnpm install && gt add -A && gt continue" |
84 | | - - label: "Let me inspect first" |
85 | | - description: "Show git diff pnpm-lock.yaml before proceeding" |
86 | | -``` |
87 | | - |
88 | | -If confirmed → Execute → Check output of `gt continue`: |
89 | | -- Another conflict → Loop back to step 3 (Gather Diagnostics) |
90 | | -- Success message → Proceed to step 6 (Success & Reminder) |
| 36 | +**Outcomes:** |
| 37 | +- **Success** → Acknowledge and skip to step 4 |
| 38 | +- **Conflicts** → Proceed to step 3 |
91 | 39 |
|
92 | | -#### Complex Conflict Resolution |
| 40 | +### 3. Route by Conflict Type |
93 | 41 |
|
94 | | -For each non-lockfile conflict: |
| 42 | +Analyze conflicted files from status above: |
95 | 43 |
|
96 | | -**a) Show the conflict**: |
97 | | -```bash |
98 | | -git diff <file> |
99 | | -``` |
100 | | - |
101 | | -**b) Explain the conflict** (extract from diff): |
102 | | -- What changed in base (HEAD) |
103 | | -- What changed in branch (incoming) |
104 | | -- Why it conflicts |
| 44 | +**Only pnpm-lock.yaml conflicted?** |
| 45 | +→ See [lockfile-conflict.md](lockfile-conflict.md) |
105 | 46 |
|
106 | | -**c) Ask resolution strategy** using AskUserQuestion: |
107 | | -``` |
108 | | -question: "How to resolve <file>?" |
109 | | -header: "Resolution" |
110 | | -options: |
111 | | - - label: "--theirs (main's version)" |
112 | | - description: "Accept base branch - good for style/formatting consistency" |
113 | | - - label: "--ours (branch's version)" |
114 | | - description: "Keep your branch changes - good for features/dependencies" |
115 | | - - label: "Manual edit" |
116 | | - description: "I'll resolve it manually, just continue after I'm done" |
117 | | - - label: "Show original file" |
118 | | - description: "Show git show HEAD:<file> and git show :<stage>:<file> to inspect" |
119 | | -``` |
| 47 | +**Multiple files conflicted?** |
| 48 | +→ See [complex-conflict.md](complex-conflict.md) |
120 | 49 |
|
121 | | -**d) Execute choice**: |
122 | | -- `--theirs`: `git checkout --theirs <file>` |
123 | | -- `--ours`: `git checkout --ours <file>` |
124 | | -- Manual: Wait for user confirmation |
125 | | -- Show original: Display and ask again |
126 | | - |
127 | | -**e) After all non-lockfile conflicts resolved**: |
128 | | -```bash |
129 | | -pnpm install && gt add -A && gt continue |
130 | | -``` |
| 50 | +**Unexpected errors or state?** |
| 51 | +→ See [troubleshooting.md](troubleshooting.md) |
131 | 52 |
|
132 | | -**f) Check output of `gt continue`**: |
133 | | -- Another conflict → Loop back to step 3 (Gather Diagnostics) |
134 | | -- Success message → Proceed to step 6 (Success & Reminder) |
| 53 | +### 4. Success |
135 | 54 |
|
136 | | -### 5. Handle Broken Lockfile |
137 | | - |
138 | | -If diagnostics show "broken lockfile" warning: |
139 | | - |
140 | | -Use AskUserQuestion: |
141 | | -``` |
142 | | -question: "Lockfile is corrupted. Delete and regenerate?" |
143 | | -header: "Broken Lockfile" |
144 | | -options: |
145 | | - - label: "Yes, delete and regenerate" |
146 | | - description: "rm pnpm-lock.yaml && pnpm install && gt add -A && gt continue" |
147 | | - - label: "Try pnpm install first" |
148 | | - description: "pnpm might auto-fix, try without deleting first" |
149 | | -``` |
150 | | - |
151 | | -After executing choice, check output of command: |
152 | | -- Another conflict → Loop back to step 3 (Gather Diagnostics) |
153 | | -- Success message → Proceed to step 6 (Success & Reminder) |
154 | | - |
155 | | -### 6. Success & Reminder |
156 | | - |
157 | | -When `gt restack` completes without conflicts: |
158 | | - |
159 | | -``` |
160 | 55 | Restack completed successfully! |
161 | 56 |
|
162 | | -Next step: Force push your stack |
163 | | - gt stack submit --force |
164 | | - # Or individual branch: |
165 | | - git push --force-with-lease origin <branch-name> |
166 | | -
|
167 | | -Note: Always use --force-with-lease for safety |
168 | | -``` |
169 | | - |
170 | | -## Quick Reference |
171 | | - |
172 | | -**Simple lockfile conflict**: |
173 | | -```bash |
174 | | -pnpm install && gt add -A && gt continue |
175 | | -``` |
| 57 | +**Next step:** Force push your stack |
176 | 58 |
|
177 | | -**Multiple files conflicted**: |
178 | 59 | ```bash |
179 | | -git diff <file> # Inspect |
180 | | -git checkout --ours/--theirs <file> # Resolve |
181 | | -pnpm install && gt add -A && gt continue |
| 60 | +gt stack submit --force |
| 61 | +# Or individual branch: |
| 62 | +git push --force-with-lease origin <branch-name> |
182 | 63 | ``` |
183 | 64 |
|
184 | | -**Broken lockfile**: |
185 | | -```bash |
186 | | -rm pnpm-lock.yaml |
187 | | -pnpm install && gt add -A && gt continue |
188 | | -``` |
189 | | - |
190 | | -**Cancel restack**: |
191 | | -```bash |
192 | | -gt abort |
193 | | -``` |
194 | | - |
195 | | -## Resolution Strategy Guide |
196 | | - |
197 | | -**When to use `--theirs` (accept main's version)**: |
198 | | -- Style/formatting conflicts (e.g., quoted vs unquoted YAML) |
199 | | -- Configuration files where consistency with main matters |
200 | | -- Files you didn't intentionally change |
201 | | - |
202 | | -**When to use `--ours` (keep branch's version)**: |
203 | | -- Your branch added dependencies (e.g., pnpm-workspace.yaml) |
204 | | -- Feature changes you need to preserve |
205 | | -- Files where your changes are the whole point |
206 | | - |
207 | | -**Rule of thumb**: When in doubt, choose consistency with main (`--theirs`). |
208 | | - |
209 | | -## Troubleshooting |
210 | | - |
211 | | -**Problem**: `gt continue` fails with error |
212 | | -**Solution**: Check `git status` for unresolved conflicts or unstaged files |
213 | | - |
214 | | -**Problem**: pnpm install shows warnings about bin files |
215 | | -**Solution**: Usually safe to ignore - supabase CLI has known installation quirks |
216 | | - |
217 | | -**Problem**: Not sure whether to use --ours or --theirs |
218 | | -**Solution**: Skill will show both versions and explain - use AskUserQuestion to decide |
219 | | - |
220 | | -**Problem**: Multiple files conflicted, unclear which to resolve first |
221 | | -**Solution**: Skill resolves non-lockfiles first, then regenerates lockfile last |
| 65 | +**Note:** Always use `--force-with-lease` for safety |
0 commit comments