Skip to content

Commit 132c6e5

Browse files
authored
docs(FR-2019): add gt absorb support to amend-staged-changes workflow (#5231)
1 parent e7c1f80 commit 132c6e5

1 file changed

Lines changed: 183 additions & 46 deletions

File tree

.claude/commands/amend-staged-changes.md

Lines changed: 183 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@ If no argument is provided, PR description will only be updated if there are sta
2020
```
2121
0. Verify MCP authentication
2222
1. Verify existing PR context
23-
2. Amend changes to current commit
24-
3. Push updated commit
25-
4. Update PR description (if needed)
26-
5. Display summary
23+
2. Analyze staged changes with gt absorb --dry-run
24+
3. Determine optimal commit placement (absorb vs amend)
25+
4. User confirmation with absorb analysis
26+
5. Apply changes (absorb or amend)
27+
6. Push updated commits
28+
7. Update PR description (if needed)
29+
8. Display summary
2730
```
2831

2932
## Detailed Process
3033

3134
### Step 0: Verify MCP Authentication (MUST BE FIRST)
3235

33-
> **⚠️ CRITICAL**: This step MUST be executed BEFORE any other operation. Do NOT skip or defer this step. Do NOT read files, check git status, or perform any other action until MCP authentication is verified.
36+
> **CRITICAL**: This step MUST be executed BEFORE any other operation. Do NOT skip or defer this step. Do NOT read files, check git status, or perform any other action until MCP authentication is verified.
3437
3538
Verify that Atlassian MCP is authenticated before starting the workflow.
3639

@@ -44,7 +47,7 @@ mcp__Atlassian__atlassianUserInfo
4447
- Inform the user that Atlassian MCP needs re-authentication
4548
- Provide guidance on how to re-authenticate:
4649
```
47-
⚠️ MCP Authentication Required
50+
MCP Authentication Required
4851
4952
Atlassian MCP needs re-authentication.
5053
Please re-authenticate via MCP settings and run the command again.
@@ -72,7 +75,7 @@ git diff --cached --stat
7275

7376
**If no PR exists for current branch:**
7477
```
75-
⚠️ No PR Found
78+
No PR Found
7679
7780
Current branch does not have an associated PR.
7881
Use /submit-staged-changes to create a new Jira issue and PR.
@@ -83,31 +86,88 @@ Use /submit-staged-changes to create a new Jira issue and PR.
8386
- Extract PR number, title, URL, and current body
8487
- Proceed to Step 2
8588

86-
### Step 2: Analyze Changes
89+
### Step 2: Analyze Changes with gt absorb
8790

8891
```bash
8992
# View staged changes
9093
git diff --cached
9194

92-
# View current commit message
93-
git log -1 --format="%B"
95+
# Run gt absorb in dry-run mode to analyze where changes could go
96+
mcp__graphite__run_gt_cmd with args: ["absorb", "--dry-run"]
9497
```
9598

96-
- Review staged changes to understand what's being amended
97-
- If no staged changes and `--update-desc` not provided:
98-
```
99-
ℹ️ No Staged Changes
99+
**gt absorb Analysis:**
100+
- `gt absorb` analyzes staged hunks and determines which commits in the stack they logically belong to
101+
- It considers the blame of modified lines to find the original commit that introduced them
102+
- Dry-run shows which changes would go to which commits WITHOUT making changes
100103

101-
No staged changes to amend. Use --update-desc flag to update PR description only.
102-
Or stage your changes first:
103-
git add <files>
104-
```
105-
- Exit the workflow
104+
**If no staged changes and `--update-desc` not provided:**
105+
```
106+
No Staged Changes
107+
108+
No staged changes to amend. Use --update-desc flag to update PR description only.
109+
Or stage your changes first:
110+
git add <files>
111+
```
112+
- Exit the workflow
113+
114+
### Step 3: Evaluate Absorb Results
115+
116+
Analyze the `gt absorb --dry-run` output and determine the best approach:
106117

107-
### Step 3: User Confirmation
118+
**Scenario A: All changes belong to current commit**
119+
- No cross-PR dependencies
120+
- Simple amend is appropriate
108121

109-
**IMPORTANT**: Present confirmation before making changes:
122+
**Scenario B: Changes can be absorbed into different commits**
123+
- Some hunks belong to commits in other PRs in the stack
124+
- Consider separation of concerns between PRs
125+
- Evaluate if absorbing maintains clean PR boundaries
126+
127+
**Scenario C: Mixed - some absorb, some amend**
128+
- Some changes fit better in downstack PRs
129+
- Some changes are new to current PR
130+
131+
**Decision Criteria:**
132+
1. **Separation of Concerns**: Does absorbing maintain clean PR boundaries?
133+
2. **PR Dependencies**: Will absorbing create unintended dependencies?
134+
3. **Review Impact**: How will absorbed changes affect PRs already under review?
135+
4. **Logical Grouping**: Do the changes logically belong together?
136+
137+
### Step 4: User Confirmation with Absorb Analysis
138+
139+
**IMPORTANT**: Present confirmation with detailed absorb analysis:
140+
141+
**If absorb candidates exist:**
142+
```
143+
AskUserQuestion({
144+
questions: [{
145+
question: "How would you like to apply the staged changes?",
146+
header: "Change Placement",
147+
multiSelect: false,
148+
options: [
149+
{
150+
label: "Absorb to Best Fit (Recommended)",
151+
description: "gt absorb analysis:\n\n[Absorb dry-run output]\n\nThis distributes changes to the commits where they logically belong, maintaining clean PR separation."
152+
},
153+
{
154+
label: "Amend Current Only",
155+
description: "Add all changes to current commit only.\nUse when changes are specific to this PR regardless of file history."
156+
},
157+
{
158+
label: "Review Details First",
159+
description: "Show detailed analysis of each hunk and its target commit before deciding."
160+
},
161+
{
162+
label: "Cancel",
163+
description: "Don't make any changes"
164+
}
165+
]
166+
}]
167+
})
168+
```
110169

170+
**If no absorb candidates (all changes for current commit):**
111171
```
112172
AskUserQuestion({
113173
questions: [{
@@ -132,26 +192,60 @@ AskUserQuestion({
132192
})
133193
```
134194

135-
### Step 4: Amend Commit
195+
**If user selects "Review Details First":**
196+
Present detailed breakdown:
197+
```
198+
Absorb Analysis Details:
199+
200+
Commit abc1234 (PR #1001 - feat: add user settings)
201+
└── e2e/user/user-settings.spec.ts:45-52 (test fix)
202+
203+
Commit def5678 (PR #1002 - fix: login validation) [CURRENT]
204+
└── src/components/LoginForm.tsx:23-30 (new code)
205+
└── src/utils/validation.ts:15-20 (modification)
136206
207+
Commit ghi9012 (PR #1003 - refactor: auth flow)
208+
└── No changes would be absorbed
209+
210+
Considerations:
211+
- PR #1001 is already approved - absorbing may require re-review
212+
- Changes to user-settings.spec.ts originated from PR #1001's original work
213+
```
214+
215+
### Step 5: Apply Changes
216+
217+
**If user selected "Absorb to Best Fit":**
218+
```
219+
# Apply absorb
220+
mcp__graphite__run_gt_cmd with args: ["absorb"]
221+
```
222+
223+
This will:
224+
- Distribute staged hunks to their logically appropriate commits
225+
- Automatically restack affected branches
226+
- Prepare for pushing multiple PRs if needed
227+
228+
**If user selected "Amend Current Only":**
137229
```
138230
# Amend staged changes to current commit
139231
mcp__graphite__run_gt_cmd with args: ["modify", "--all"]
140232
```
141233

142-
This command:
143-
- Adds staged changes to the current commit
144-
- Keeps the existing commit message
145-
- Prepares for pushing
234+
This will:
235+
- Add all staged changes to the current commit
236+
- Keep the existing commit message
237+
- Prepare for pushing
146238

147-
### Step 5: Push Updated Commit
239+
### Step 6: Push Updated Commits
148240

149241
```
150-
# Push amended commit (force push)
151-
mcp__graphite__run_gt_cmd with args: ["submit"]
242+
# Push amended/absorbed commits (force push)
243+
mcp__graphite__run_gt_cmd with args: ["submit", "--stack", "--no-interactive"]
152244
```
153245

154-
### Step 6: Update PR Description (Optional)
246+
**Note**: If absorb was used, multiple PRs may be updated.
247+
248+
### Step 7: Update PR Description (Optional)
155249

156250
If user selected "Amend & Update Description" or used `--update-desc` flag:
157251

@@ -175,12 +269,30 @@ EOF
175269
)"
176270
```
177271

178-
### Step 7: Display Summary
272+
### Step 8: Display Summary
179273

180-
Present a clear summary:
274+
**For Absorb:**
275+
```
276+
Absorb Complete!
277+
278+
Changes distributed across stack:
279+
280+
PR #1001 (feat: add user settings)
281+
Branch: feat/FR-1001-user-settings
282+
Files: e2e/user/user-settings.spec.ts
283+
Commit: abc1234 → abc5678 (amended)
284+
285+
PR #1002 (fix: login validation) [CURRENT]
286+
Branch: fix/FR-1002-login-validation
287+
Files: src/components/LoginForm.tsx, src/utils/validation.ts
288+
Commit: def1234 → def5678 (amended)
181289
290+
All affected PRs have been pushed.
182291
```
183-
✅ Amendment Complete!
292+
293+
**For Simple Amend:**
294+
```
295+
Amendment Complete!
184296
185297
Pull Request: #YYYY
186298
https://github.com/lablup/backend.ai-webui/pull/YYYY
@@ -199,7 +311,7 @@ Commit: abc1234 → def5678 (amended)
199311
### No Existing PR
200312
If `gh pr view` fails:
201313
```
202-
⚠️ No PR Found
314+
No PR Found
203315
204316
Current branch 'branch-name' does not have an associated PR.
205317
@@ -209,16 +321,29 @@ Options:
209321
```
210322

211323
### Graphite Sync Issues
212-
If `gt modify` fails due to sync issues:
324+
If `gt absorb` or `gt modify` fails due to sync issues:
213325
```
214326
mcp__graphite__run_gt_cmd with args: ["sync"]
215327
```
216-
Then retry the modify operation.
328+
Then retry the operation.
329+
330+
### Absorb Conflicts
331+
If `gt absorb` encounters conflicts:
332+
```
333+
Absorb Conflict
334+
335+
Some hunks could not be cleanly absorbed:
336+
- file.ts:23-30 conflicts with existing changes
337+
338+
Options:
339+
1. Resolve conflicts manually and re-run
340+
2. Use "Amend Current Only" to keep all changes in current commit
341+
```
217342

218343
### Push Conflicts
219344
If `gt submit` fails due to conflicts:
220345
```
221-
⚠️ Push Failed
346+
Push Failed
222347
223348
There may be conflicts with the remote branch.
224349
Please resolve conflicts manually:
@@ -229,21 +354,23 @@ Please resolve conflicts manually:
229354
## Important Notes
230355

231356
### Do's
232-
- Always verify PR exists before amending
233-
- Confirm with user before force-pushing
357+
- Always run `gt absorb --dry-run` first to analyze change placement
358+
- Consider PR boundaries and separation of concerns
359+
- Confirm with user before making changes, especially when absorbing
234360
- Keep PR description updated with amendment summary
235361
- Use Graphite MCP tools for git operations
236362

237363
### Don'ts
238-
- Never amend without user confirmation
239-
- Don't amend if no staged changes (unless --update-desc)
364+
- Never absorb without user confirmation
365+
- Don't absorb into PRs that are already approved without warning
366+
- Don't amend/absorb if no staged changes (unless --update-desc)
240367
- Don't use direct `git push --force` commands
241-
- Don't modify commits that are not the HEAD of the current branch
368+
- Don't modify commits that are not part of the current stack
242369

243370
## Usage Examples
244371

245372
```bash
246-
# Amend staged changes to existing PR
373+
# Amend/absorb staged changes to existing PR(s)
247374
/amend-staged-changes
248375

249376
# Update PR description only (no code changes)
@@ -254,8 +381,18 @@ Please resolve conflicts manually:
254381

255382
| Aspect | /submit-staged-changes | /amend-staged-changes |
256383
|--------|------------------------|----------------------|
257-
| Purpose | Create new Jira issue + PR | Update existing PR |
384+
| Purpose | Create new Jira issue + PR | Update existing PR(s) |
258385
| Jira | Creates new issue | No Jira changes |
259-
| Branch | Creates new branch | Uses current branch |
260-
| Commit | New commit | Amends existing commit |
386+
| Branch | Creates new branch | Uses current branch/stack |
387+
| Commit | New commit | Amends/absorbs to existing |
388+
| Stack | Single PR | Can affect multiple PRs |
261389
| Use when | Starting new work | Adding to existing work |
390+
391+
## gt absorb vs gt modify
392+
393+
| Aspect | gt absorb | gt modify |
394+
|--------|-----------|-----------|
395+
| Scope | Analyzes entire stack | Current commit only |
396+
| Placement | Auto-determines best commit | Always current commit |
397+
| Use when | Changes span multiple PRs | Changes specific to current PR |
398+
| Consideration | Maintains PR separation | Simpler, single-PR focused |

0 commit comments

Comments
 (0)