ace-git-worktree 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.ace-defaults/git/worktree.yml +250 -0
- data/.ace-defaults/nav/protocols/wfi-sources/ace-git-worktree.yml +19 -0
- data/CHANGELOG.md +957 -0
- data/LICENSE +21 -0
- data/README.md +40 -0
- data/Rakefile +14 -0
- data/docs/demo/ace-git-worktree-getting-started.gif +0 -0
- data/docs/demo/ace-git-worktree-getting-started.tape.yml +28 -0
- data/docs/demo/fixtures/README.md +3 -0
- data/docs/demo/fixtures/sample.txt +1 -0
- data/docs/getting-started.md +114 -0
- data/docs/handbook.md +38 -0
- data/docs/usage.md +334 -0
- data/exe/ace-git-worktree +24 -0
- data/handbook/agents/worktree.ag.md +189 -0
- data/handbook/skills/as-git-worktree/SKILL.md +27 -0
- data/handbook/skills/as-git-worktree-create/SKILL.md +21 -0
- data/handbook/skills/as-git-worktree-manage/SKILL.md +20 -0
- data/handbook/workflow-instructions/git/worktree-create.wf.md +262 -0
- data/handbook/workflow-instructions/git/worktree-manage.wf.md +384 -0
- data/handbook/workflow-instructions/git/worktree.wf.md +224 -0
- data/lib/ace/git/worktree/atoms/git_command.rb +121 -0
- data/lib/ace/git/worktree/atoms/path_expander.rb +189 -0
- data/lib/ace/git/worktree/atoms/slug_generator.rb +235 -0
- data/lib/ace/git/worktree/atoms/task_id_extractor.rb +91 -0
- data/lib/ace/git/worktree/cli/commands/config.rb +50 -0
- data/lib/ace/git/worktree/cli/commands/create.rb +80 -0
- data/lib/ace/git/worktree/cli/commands/list.rb +76 -0
- data/lib/ace/git/worktree/cli/commands/prune.rb +43 -0
- data/lib/ace/git/worktree/cli/commands/remove.rb +48 -0
- data/lib/ace/git/worktree/cli/commands/shared_helpers.rb +66 -0
- data/lib/ace/git/worktree/cli/commands/switch.rb +44 -0
- data/lib/ace/git/worktree/cli.rb +103 -0
- data/lib/ace/git/worktree/commands/config_command.rb +351 -0
- data/lib/ace/git/worktree/commands/create_command.rb +961 -0
- data/lib/ace/git/worktree/commands/list_command.rb +247 -0
- data/lib/ace/git/worktree/commands/prune_command.rb +260 -0
- data/lib/ace/git/worktree/commands/remove_command.rb +522 -0
- data/lib/ace/git/worktree/commands/switch_command.rb +249 -0
- data/lib/ace/git/worktree/configuration.rb +167 -0
- data/lib/ace/git/worktree/models/worktree_config.rb +502 -0
- data/lib/ace/git/worktree/models/worktree_info.rb +303 -0
- data/lib/ace/git/worktree/models/worktree_metadata.rb +294 -0
- data/lib/ace/git/worktree/molecules/config_loader.rb +125 -0
- data/lib/ace/git/worktree/molecules/current_task_linker.rb +136 -0
- data/lib/ace/git/worktree/molecules/hook_executor.rb +361 -0
- data/lib/ace/git/worktree/molecules/parent_task_resolver.rb +186 -0
- data/lib/ace/git/worktree/molecules/pr_creator.rb +253 -0
- data/lib/ace/git/worktree/molecules/task_committer.rb +329 -0
- data/lib/ace/git/worktree/molecules/task_fetcher.rb +244 -0
- data/lib/ace/git/worktree/molecules/task_pusher.rb +183 -0
- data/lib/ace/git/worktree/molecules/task_status_updater.rb +447 -0
- data/lib/ace/git/worktree/molecules/worktree_creator.rb +832 -0
- data/lib/ace/git/worktree/molecules/worktree_lister.rb +337 -0
- data/lib/ace/git/worktree/molecules/worktree_remover.rb +416 -0
- data/lib/ace/git/worktree/organisms/task_worktree_orchestrator.rb +906 -0
- data/lib/ace/git/worktree/organisms/worktree_manager.rb +714 -0
- data/lib/ace/git/worktree/version.rb +9 -0
- data/lib/ace/git/worktree.rb +215 -0
- metadata +218 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
---
|
|
2
|
+
doc-type: workflow
|
|
3
|
+
title: Manage Worktree Workflow Instruction
|
|
4
|
+
purpose: Documentation for ace-git-worktree/handbook/workflow-instructions/git/worktree-manage.wf.md
|
|
5
|
+
ace-docs:
|
|
6
|
+
last-updated: 2026-02-22
|
|
7
|
+
last-checked: 2026-03-21
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Manage Worktree Workflow Instruction
|
|
11
|
+
|
|
12
|
+
## Purpose
|
|
13
|
+
|
|
14
|
+
Manage existing git worktrees including listing, switching between, removing, and cleaning up worktrees. This workflow provides comprehensive worktree lifecycle management.
|
|
15
|
+
|
|
16
|
+
## Prerequisites
|
|
17
|
+
|
|
18
|
+
- Existing worktrees in the repository
|
|
19
|
+
- ace-git-worktree installed and configured
|
|
20
|
+
- Appropriate permissions for worktree operations
|
|
21
|
+
|
|
22
|
+
## Variables
|
|
23
|
+
|
|
24
|
+
$identifier: Worktree identifier (task ID, branch name, directory, or path)
|
|
25
|
+
$action: Management action (list, switch, remove, prune)
|
|
26
|
+
|
|
27
|
+
## Instructions
|
|
28
|
+
|
|
29
|
+
### 1. List Worktrees
|
|
30
|
+
|
|
31
|
+
**Basic Listing:**
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# List all worktrees in table format
|
|
35
|
+
ace-git-worktree list
|
|
36
|
+
|
|
37
|
+
# List with task associations
|
|
38
|
+
ace-git-worktree list --show-tasks
|
|
39
|
+
|
|
40
|
+
# List in different formats
|
|
41
|
+
ace-git-worktree list --format json
|
|
42
|
+
ace-git-worktree list --format simple
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Filtered Listing:**
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# List only task-associated worktrees
|
|
49
|
+
ace-git-worktree list --task-associated
|
|
50
|
+
|
|
51
|
+
# List only non-task worktrees
|
|
52
|
+
ace-git-worktree list --no-task-associated
|
|
53
|
+
|
|
54
|
+
# List only usable worktrees
|
|
55
|
+
ace-git-worktree list --usable
|
|
56
|
+
|
|
57
|
+
# Search by branch pattern
|
|
58
|
+
ace-git-worktree list --search auth
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 2. Switch Between Worktrees
|
|
62
|
+
|
|
63
|
+
**By Various Identifiers:**
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# Switch by task ID
|
|
67
|
+
cd $(ace-git-worktree switch 081)
|
|
68
|
+
|
|
69
|
+
# Switch by branch name
|
|
70
|
+
cd $(ace-git-worktree switch feature-branch)
|
|
71
|
+
|
|
72
|
+
# Switch by directory name
|
|
73
|
+
cd $(ace-git-worktree switch task.081)
|
|
74
|
+
|
|
75
|
+
# Switch by full path
|
|
76
|
+
cd $(ace-git-worktree switch /path/to/worktree)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Alternative Navigation:**
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Get worktree path and store in variable
|
|
83
|
+
WORKTREE_PATH=$(ace-git-worktree switch 081)
|
|
84
|
+
echo "Worktree path: $WORKTREE_PATH"
|
|
85
|
+
cd "$WORKTREE_PATH"
|
|
86
|
+
|
|
87
|
+
# List available worktrees first
|
|
88
|
+
ace-git-worktree switch --list
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### 3. Remove Worktrees
|
|
92
|
+
|
|
93
|
+
**Task-Aware Removal:**
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# Remove task worktree
|
|
97
|
+
ace-git-worktree remove --task 081
|
|
98
|
+
|
|
99
|
+
# Force remove (with uncommitted changes)
|
|
100
|
+
ace-git-worktree remove --task 081 --force
|
|
101
|
+
|
|
102
|
+
# Keep directory (remove git tracking only)
|
|
103
|
+
ace-git-worktree remove --task 081 --keep-directory
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**Traditional Removal:**
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# Remove by branch name
|
|
110
|
+
ace-git-worktree remove feature-branch
|
|
111
|
+
|
|
112
|
+
# Remove by identifier
|
|
113
|
+
ace-git-worktree remove task.081
|
|
114
|
+
|
|
115
|
+
# Remove with dry-run preview
|
|
116
|
+
ace-git-worktree remove --task 081 --dry-run
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 4. Clean Up Deleted Worktrees
|
|
120
|
+
|
|
121
|
+
**Basic Pruning:**
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
# Prune git metadata for deleted worktrees
|
|
125
|
+
ace-git-worktree prune
|
|
126
|
+
|
|
127
|
+
# Remove orphaned directories too
|
|
128
|
+
ace-git-worktree prune --cleanup-directories
|
|
129
|
+
|
|
130
|
+
# Dry run to preview changes
|
|
131
|
+
ace-git-worktree prune --dry-run
|
|
132
|
+
|
|
133
|
+
# Verbose output
|
|
134
|
+
ace-git-worktree prune --verbose
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 5. Configuration Management
|
|
138
|
+
|
|
139
|
+
**Show Configuration:**
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
# Show current configuration
|
|
143
|
+
ace-git-worktree config
|
|
144
|
+
|
|
145
|
+
# Validate configuration
|
|
146
|
+
ace-git-worktree config --validate
|
|
147
|
+
|
|
148
|
+
# Show configuration file locations
|
|
149
|
+
ace-git-worktree config --files
|
|
150
|
+
|
|
151
|
+
# Show detailed configuration
|
|
152
|
+
ace-git-worktree config --show
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Advanced Operations
|
|
156
|
+
|
|
157
|
+
### Bulk Management
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
# Get worktree status for all tasks
|
|
161
|
+
ace-git-worktree list --format json --show-tasks | jq '.worktrees'
|
|
162
|
+
|
|
163
|
+
# Count worktrees by type
|
|
164
|
+
ace-git-worktree list --show-tasks | grep "Task" | wc -l
|
|
165
|
+
|
|
166
|
+
# Find worktrees with specific patterns
|
|
167
|
+
ace-git-worktree list --search "bug" --format simple
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Search and Filter
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
# Search worktrees by multiple criteria
|
|
174
|
+
ace-git-worktree list --search auth --task-associated --format json
|
|
175
|
+
|
|
176
|
+
# Filter by usability
|
|
177
|
+
ace-git-worktree list --usable --format simple
|
|
178
|
+
|
|
179
|
+
# Show only worktrees with branches
|
|
180
|
+
ace-git-worktree list | grep -v "bare\|detached"
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Status and Monitoring
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
# Get comprehensive status
|
|
187
|
+
ace-git-worktree list --show-tasks --format json
|
|
188
|
+
|
|
189
|
+
# Check specific worktree
|
|
190
|
+
ace-git-worktree switch 081 --verbose
|
|
191
|
+
|
|
192
|
+
# Validate setup
|
|
193
|
+
ace-git-worktree config --validate
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Automation and Scripting
|
|
197
|
+
|
|
198
|
+
### JSON Output for Scripts
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
# Get all worktrees as JSON
|
|
202
|
+
WORKTREES=$(ace-git-worktree list --format json --show-tasks)
|
|
203
|
+
|
|
204
|
+
# Extract specific information
|
|
205
|
+
echo "$WORKTREES" | jq '.worktrees[] | select(.task_id == "081")'
|
|
206
|
+
echo "$WORKTREES" | jq '.worktrees[] | .path'
|
|
207
|
+
echo "$WORKTREES" | jq '.worktrees | length'
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Batch Operations
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
# Remove multiple worktrees
|
|
214
|
+
for task_id in 081 082 083; do
|
|
215
|
+
ace-git-worktree remove --task "$task_id" --force
|
|
216
|
+
done
|
|
217
|
+
|
|
218
|
+
# Switch between worktrees
|
|
219
|
+
WORKTREES=("081" "082" "083")
|
|
220
|
+
for task_id in "${WORKTREES[@]}"; do
|
|
221
|
+
echo "Switching to task $task_id"
|
|
222
|
+
cd "$(ace-git-worktree switch "$task_id")"
|
|
223
|
+
# Do work in each worktree...
|
|
224
|
+
cd ..
|
|
225
|
+
done
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Conditional Operations
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
# Only remove if worktree exists
|
|
232
|
+
if ace-git-worktree switch 081 --help > /dev/null 2>&1; then
|
|
233
|
+
ace-git-worktree remove --task 081
|
|
234
|
+
fi
|
|
235
|
+
|
|
236
|
+
# Check if worktrees need cleanup
|
|
237
|
+
if ace-git-worktree prune --dry-run | grep -q "Pruning"; then
|
|
238
|
+
ace-git-worktree prune --cleanup-directories
|
|
239
|
+
fi
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Error Recovery
|
|
243
|
+
|
|
244
|
+
### Common Issues
|
|
245
|
+
|
|
246
|
+
**Worktree Not Found:**
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
# List available worktrees
|
|
250
|
+
ace-git-worktree list
|
|
251
|
+
|
|
252
|
+
# Search for similar identifiers
|
|
253
|
+
ace-git-worktree list --search "081"
|
|
254
|
+
|
|
255
|
+
# Try different identifier formats
|
|
256
|
+
ace-git-worktree switch task.081
|
|
257
|
+
ace-git-worktree switch 081-fix-auth
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**Permission Issues:**
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
# Check worktree directory permissions
|
|
264
|
+
ls -la .ace-wt/
|
|
265
|
+
|
|
266
|
+
# Fix permissions if needed
|
|
267
|
+
chmod -R 755 .ace-wt/
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
**Git Repository Issues:**
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
# Check git status in worktree
|
|
274
|
+
cd $(ace-git-worktree switch 081)
|
|
275
|
+
git status
|
|
276
|
+
|
|
277
|
+
# Fix git issues if needed
|
|
278
|
+
git checkout main
|
|
279
|
+
git branch -D 081-fix-auth # if needed
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Safety Checks
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
# Check removal safety before removing
|
|
286
|
+
ace-git-worktree switch 081 --help > /dev/null
|
|
287
|
+
if [ $? -eq 0 ]; then
|
|
288
|
+
echo "Worktree exists, proceeding with removal"
|
|
289
|
+
ace-git-worktree remove --task 081 --dry-run
|
|
290
|
+
else
|
|
291
|
+
echo "Worktree not found, skipping removal"
|
|
292
|
+
fi
|
|
293
|
+
|
|
294
|
+
# Check for uncommitted changes
|
|
295
|
+
cd $(ace-git-worktree switch 081)
|
|
296
|
+
if [ -n "$(git status --porcelain)" ]; then
|
|
297
|
+
echo "Worktree has uncommitted changes"
|
|
298
|
+
git status
|
|
299
|
+
else
|
|
300
|
+
echo "Worktree is clean"
|
|
301
|
+
fi
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
## Integration with Development Workflow
|
|
305
|
+
|
|
306
|
+
### Daily Workflow Management
|
|
307
|
+
|
|
308
|
+
```bash
|
|
309
|
+
#!/bin/bash
|
|
310
|
+
# Daily worktree management script
|
|
311
|
+
|
|
312
|
+
# 1. Check current worktree status
|
|
313
|
+
echo "=== Current Worktree Status ==="
|
|
314
|
+
ace-git-worktree list --show-tasks --format simple
|
|
315
|
+
|
|
316
|
+
# 2. Clean up if needed
|
|
317
|
+
echo "=== Cleanup Check ==="
|
|
318
|
+
if ace-git-worktree prune --dry-run | grep -q "Pruning"; then
|
|
319
|
+
echo "Cleaning up deleted worktrees..."
|
|
320
|
+
ace-git-worktree prune --cleanup-directories
|
|
321
|
+
else
|
|
322
|
+
echo "No cleanup needed"
|
|
323
|
+
fi
|
|
324
|
+
|
|
325
|
+
# 3. Show configuration
|
|
326
|
+
echo "=== Configuration ==="
|
|
327
|
+
ace-git-worktree config --validate
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Task Completion Workflow
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
#!/bin/bash
|
|
334
|
+
# Complete task and cleanup worktree
|
|
335
|
+
|
|
336
|
+
TASK_ID="$1"
|
|
337
|
+
if [ -z "$TASK_ID" ]; then
|
|
338
|
+
echo "Usage: $0 <task-id>"
|
|
339
|
+
exit 1
|
|
340
|
+
fi
|
|
341
|
+
|
|
342
|
+
# 1. Switch to worktree and check status
|
|
343
|
+
echo "Checking worktree for task $TASK_ID..."
|
|
344
|
+
WORKTREE_PATH=$(ace-git-worktree switch "$TASK_ID")
|
|
345
|
+
cd "$WORKTREE_PATH"
|
|
346
|
+
|
|
347
|
+
# 2. Check for uncommitted changes
|
|
348
|
+
if [ -n "$(git status --porcelain)" ]; then
|
|
349
|
+
echo "WARNING: Worktree has uncommitted changes"
|
|
350
|
+
git status
|
|
351
|
+
read -p "Continue with removal? (y/N): " -n 1 -r
|
|
352
|
+
echo
|
|
353
|
+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
354
|
+
echo "Aborting removal"
|
|
355
|
+
exit 1
|
|
356
|
+
fi
|
|
357
|
+
fi
|
|
358
|
+
|
|
359
|
+
# 3. Return to main and remove worktree
|
|
360
|
+
cd ..
|
|
361
|
+
echo "Removing worktree for task $TASK_ID..."
|
|
362
|
+
ace-git-worktree remove --task "$TASK_ID"
|
|
363
|
+
|
|
364
|
+
# 4. Clean up if needed
|
|
365
|
+
ace-git-worktree prune
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
## Success Criteria
|
|
369
|
+
|
|
370
|
+
- Worktrees listed with correct information
|
|
371
|
+
- Successfully switched to target worktree
|
|
372
|
+
- Worktrees removed cleanly with proper cleanup
|
|
373
|
+
- Deleted worktree metadata pruned from git
|
|
374
|
+
- Configuration validated and accessible
|
|
375
|
+
- Automation scripts work correctly
|
|
376
|
+
- Error conditions handled gracefully
|
|
377
|
+
|
|
378
|
+
## Response Template
|
|
379
|
+
|
|
380
|
+
**Action:** [list/switch/remove/prune/config]
|
|
381
|
+
**Worktree(s):** [Count and type of worktrees affected]
|
|
382
|
+
**Location(s):** [Paths involved]
|
|
383
|
+
**Status:** [Current state after operation]
|
|
384
|
+
**Next Steps:** [Recommended follow-up actions]
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
---
|
|
2
|
+
doc-type: workflow
|
|
3
|
+
title: Worktree Workflow
|
|
4
|
+
purpose: worktree workflow instruction
|
|
5
|
+
ace-docs:
|
|
6
|
+
last-updated: 2026-03-06
|
|
7
|
+
last-checked: 2026-03-21
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Worktree Workflow
|
|
11
|
+
|
|
12
|
+
## Purpose
|
|
13
|
+
|
|
14
|
+
Manage git worktrees with task-aware automation and traditional operations using ace-git-worktree CLI.
|
|
15
|
+
|
|
16
|
+
## Primary Tool: ace-git-worktree
|
|
17
|
+
|
|
18
|
+
All operations use the **ace-git-worktree** command.
|
|
19
|
+
|
|
20
|
+
## Task-Aware Operations
|
|
21
|
+
|
|
22
|
+
### Create Worktree for Task
|
|
23
|
+
```bash
|
|
24
|
+
# Create worktree for task (recommended)
|
|
25
|
+
ace-git-worktree create --task 081
|
|
26
|
+
|
|
27
|
+
# With dry-run preview
|
|
28
|
+
ace-git-worktree create --task 081 --dry-run
|
|
29
|
+
|
|
30
|
+
# Skip automatic operations
|
|
31
|
+
ace-git-worktree create --task 081 --no-commit --no-status-update
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Switch to Task Worktree
|
|
35
|
+
```bash
|
|
36
|
+
# Switch by task ID
|
|
37
|
+
ace-git-worktree switch 081
|
|
38
|
+
|
|
39
|
+
# Verbose output
|
|
40
|
+
ace-git-worktree switch 081 --verbose
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Remove Task Worktree
|
|
44
|
+
```bash
|
|
45
|
+
# Remove task worktree
|
|
46
|
+
ace-git-worktree remove --task 081
|
|
47
|
+
|
|
48
|
+
# Preview removal
|
|
49
|
+
ace-git-worktree remove --task 081 --dry-run
|
|
50
|
+
|
|
51
|
+
# Force removal with uncommitted changes
|
|
52
|
+
ace-git-worktree remove --task 081 --force
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Traditional Worktree Operations
|
|
56
|
+
|
|
57
|
+
### Create Worktree for Branch
|
|
58
|
+
```bash
|
|
59
|
+
# Create for branch
|
|
60
|
+
ace-git-worktree create feature-branch
|
|
61
|
+
|
|
62
|
+
# Custom path
|
|
63
|
+
ace-git-worktree create feature-branch --path ../custom-path
|
|
64
|
+
|
|
65
|
+
# Without mise trust
|
|
66
|
+
ace-git-worktree create feature-branch --no-mise-trust
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### List Worktrees
|
|
70
|
+
```bash
|
|
71
|
+
# List all worktrees
|
|
72
|
+
ace-git-worktree list
|
|
73
|
+
|
|
74
|
+
# Show task associations
|
|
75
|
+
ace-git-worktree list --show-tasks
|
|
76
|
+
|
|
77
|
+
# Filter by task association
|
|
78
|
+
ace-git-worktree list --task-associated
|
|
79
|
+
|
|
80
|
+
# Output formats
|
|
81
|
+
ace-git-worktree list --format json
|
|
82
|
+
ace-git-worktree list --format table
|
|
83
|
+
ace-git-worktree list --format simple
|
|
84
|
+
|
|
85
|
+
# Search/filter
|
|
86
|
+
ace-git-worktree list --search "081"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Switch Worktree
|
|
90
|
+
```bash
|
|
91
|
+
# By branch name
|
|
92
|
+
ace-git-worktree switch feature-branch
|
|
93
|
+
|
|
94
|
+
# By directory name
|
|
95
|
+
ace-git-worktree switch task.081
|
|
96
|
+
|
|
97
|
+
# By path
|
|
98
|
+
ace-git-worktree switch ../as-task.081
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Remove Worktree
|
|
102
|
+
```bash
|
|
103
|
+
# By branch name
|
|
104
|
+
ace-git-worktree remove feature-branch
|
|
105
|
+
|
|
106
|
+
# Keep directory
|
|
107
|
+
ace-git-worktree remove feature-branch --keep-directory
|
|
108
|
+
|
|
109
|
+
# Force removal
|
|
110
|
+
ace-git-worktree remove feature-branch --force
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Cleanup Operations
|
|
114
|
+
|
|
115
|
+
### Prune Deleted Worktrees
|
|
116
|
+
```bash
|
|
117
|
+
# Prune git worktree metadata
|
|
118
|
+
ace-git-worktree prune
|
|
119
|
+
|
|
120
|
+
# Also remove orphaned directories
|
|
121
|
+
ace-git-worktree prune --cleanup-directories
|
|
122
|
+
|
|
123
|
+
# Dry-run preview
|
|
124
|
+
ace-git-worktree prune --cleanup-directories --dry-run
|
|
125
|
+
|
|
126
|
+
# Verbose output
|
|
127
|
+
ace-git-worktree prune --verbose
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Configuration
|
|
131
|
+
|
|
132
|
+
### Show Configuration
|
|
133
|
+
```bash
|
|
134
|
+
# Show current configuration
|
|
135
|
+
ace-git-worktree config --show
|
|
136
|
+
|
|
137
|
+
# Validate configuration
|
|
138
|
+
ace-git-worktree config --validate
|
|
139
|
+
|
|
140
|
+
# Show configuration file locations
|
|
141
|
+
ace-git-worktree config --files
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Configuration File
|
|
145
|
+
|
|
146
|
+
Configuration from `.ace/git/worktree.yml`:
|
|
147
|
+
|
|
148
|
+
```yaml
|
|
149
|
+
git:
|
|
150
|
+
worktree:
|
|
151
|
+
root_path: ".ace-wt"
|
|
152
|
+
mise_trust_auto: true
|
|
153
|
+
task:
|
|
154
|
+
directory_format: "task.{id}"
|
|
155
|
+
branch_format: "{id}-{slug}"
|
|
156
|
+
auto_mark_in_progress: true
|
|
157
|
+
auto_commit_task: true
|
|
158
|
+
add_worktree_metadata: true
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Command Reference
|
|
162
|
+
|
|
163
|
+
### create
|
|
164
|
+
- `--task <task-id>`: Create worktree for specific task
|
|
165
|
+
- `--path <path>`: Custom worktree path
|
|
166
|
+
- `--dry-run`: Preview without creating
|
|
167
|
+
- `--no-mise-trust`: Skip automatic mise trust
|
|
168
|
+
- `--no-status-update`: Skip task status update
|
|
169
|
+
- `--no-commit`: Skip committing task changes
|
|
170
|
+
|
|
171
|
+
### list
|
|
172
|
+
- `--format <format>`: Output format (table, json, simple)
|
|
173
|
+
- `--show-tasks`: Include task associations
|
|
174
|
+
- `--task-associated`: Filter by task association
|
|
175
|
+
- `--search <pattern>`: Filter by search pattern
|
|
176
|
+
|
|
177
|
+
### switch
|
|
178
|
+
- `identifier`: Worktree identifier (task ID, branch name, directory, path)
|
|
179
|
+
- `--verbose`: Show detailed information
|
|
180
|
+
|
|
181
|
+
### remove
|
|
182
|
+
- `--task <task-id>`: Remove task worktree
|
|
183
|
+
- `--force`: Force removal with uncommitted changes
|
|
184
|
+
- `--keep-directory`: Keep worktree directory
|
|
185
|
+
- `--dry-run`: Preview without removing
|
|
186
|
+
|
|
187
|
+
### prune
|
|
188
|
+
- `--cleanup-directories`: Remove orphaned directories
|
|
189
|
+
- `--dry-run`: Preview changes
|
|
190
|
+
- `--verbose`: Detailed output
|
|
191
|
+
|
|
192
|
+
### config
|
|
193
|
+
- `--show`: Show current configuration
|
|
194
|
+
- `--validate`: Validate configuration
|
|
195
|
+
- `--files`: Show configuration file locations
|
|
196
|
+
|
|
197
|
+
## Error Handling
|
|
198
|
+
|
|
199
|
+
The CLI handles common error conditions:
|
|
200
|
+
- **Task not found**: Validates task ID existence before creation
|
|
201
|
+
- **Not in git repository**: Checks git repository status
|
|
202
|
+
- **Configuration invalid**: Validates configuration before operations
|
|
203
|
+
- **Worktree conflicts**: Detects existing worktrees and provides alternatives
|
|
204
|
+
- **Permission issues**: Validates directory permissions and access
|
|
205
|
+
- **Uncommitted changes**: Warns about changes before removal
|
|
206
|
+
|
|
207
|
+
## Best Practices
|
|
208
|
+
|
|
209
|
+
1. **Use task-aware creation** for ACE workflow integration
|
|
210
|
+
2. **Validate configuration** before operations
|
|
211
|
+
3. **Use dry-run** to preview changes
|
|
212
|
+
4. **Clean up worktrees** when tasks are complete
|
|
213
|
+
5. **Prune regularly** to maintain clean repository state
|
|
214
|
+
6. **Check git status** before removing worktrees with changes
|
|
215
|
+
|
|
216
|
+
## Response Format
|
|
217
|
+
|
|
218
|
+
```markdown
|
|
219
|
+
**Operation:** [create/list/switch/remove/prune/config]
|
|
220
|
+
**Worktree(s):** [Worktree information]
|
|
221
|
+
**Status:** [Success/Failure with details]
|
|
222
|
+
**Location(s):** [Relevant paths]
|
|
223
|
+
**Next Steps:** [Recommended follow-up actions]
|
|
224
|
+
```
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ace
|
|
4
|
+
module Git
|
|
5
|
+
module Worktree
|
|
6
|
+
module Atoms
|
|
7
|
+
# Git command execution atom
|
|
8
|
+
#
|
|
9
|
+
# Provides a thin wrapper around ace-git's CommandExecutor
|
|
10
|
+
# for safe git command execution with proper error handling.
|
|
11
|
+
# This adapter maintains backward compatibility with the original API
|
|
12
|
+
# while delegating to the consolidated ace-git package.
|
|
13
|
+
#
|
|
14
|
+
# @example Execute a git worktree command
|
|
15
|
+
# GitCommand.execute("worktree", "add", "/path/to/worktree", "-b", "feature-branch")
|
|
16
|
+
#
|
|
17
|
+
# @example Handle command failures
|
|
18
|
+
# result = GitCommand.execute("worktree", "add", "/invalid/path")
|
|
19
|
+
# unless result[:success]
|
|
20
|
+
# puts "Error: #{result[:error]}"
|
|
21
|
+
# end
|
|
22
|
+
class GitCommand
|
|
23
|
+
# Fallback timeout for git commands (30 seconds)
|
|
24
|
+
# Used only when config is unavailable
|
|
25
|
+
FALLBACK_TIMEOUT = 30
|
|
26
|
+
|
|
27
|
+
class << self
|
|
28
|
+
# Get default timeout from config or fallback
|
|
29
|
+
# @return [Integer] Timeout in seconds
|
|
30
|
+
def default_timeout
|
|
31
|
+
Ace::Git::Worktree.default_timeout
|
|
32
|
+
rescue
|
|
33
|
+
FALLBACK_TIMEOUT
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Execute a git command safely using ace-git's CommandExecutor
|
|
37
|
+
#
|
|
38
|
+
# @param args [Array<String>] Command arguments (command and its arguments)
|
|
39
|
+
# @param timeout [Integer, nil] Timeout in seconds (uses config default if nil)
|
|
40
|
+
# @return [Hash] Result hash with :success, :output, :error, :exit_code keys
|
|
41
|
+
#
|
|
42
|
+
# @example
|
|
43
|
+
# result = GitCommand.execute("worktree", "list")
|
|
44
|
+
# # => { success: true, output: "/path/to/worktree abc123 [branch-name]\n", error: "", exit_code: 0 }
|
|
45
|
+
def execute(*args, timeout: nil)
|
|
46
|
+
timeout ||= default_timeout
|
|
47
|
+
# Ensure all arguments are strings
|
|
48
|
+
string_args = args.map(&:to_s)
|
|
49
|
+
|
|
50
|
+
# Delegate to ace-git's CommandExecutor
|
|
51
|
+
# Note: CommandExecutor expects "git" as first argument
|
|
52
|
+
result = Ace::Git::Atoms::CommandExecutor.execute("git", *string_args, timeout:)
|
|
53
|
+
|
|
54
|
+
# Normalize ace-git result keys for legacy compatibility
|
|
55
|
+
{
|
|
56
|
+
success: result[:success],
|
|
57
|
+
output: result[:output].to_s,
|
|
58
|
+
error: result[:error].to_s,
|
|
59
|
+
exit_code: result[:exit_code] || 0
|
|
60
|
+
}
|
|
61
|
+
rescue => e
|
|
62
|
+
# Handle unexpected exceptions from ace-git to maintain defensive behavior
|
|
63
|
+
{
|
|
64
|
+
success: false,
|
|
65
|
+
output: "",
|
|
66
|
+
error: "Unexpected error: #{e.message}",
|
|
67
|
+
exit_code: 1
|
|
68
|
+
}
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Execute a git worktree command
|
|
72
|
+
#
|
|
73
|
+
# @param args [Array<String>] Worktree subcommand arguments
|
|
74
|
+
# @param timeout [Integer, nil] Timeout in seconds (uses config default if nil)
|
|
75
|
+
# @return [Hash] Result hash with command execution details
|
|
76
|
+
#
|
|
77
|
+
# @example
|
|
78
|
+
# result = GitCommand.worktree("add", "/path/to/worktree", "-b", "feature-branch")
|
|
79
|
+
def worktree(*args, timeout: nil)
|
|
80
|
+
execute("worktree", *args, timeout: timeout)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Check if git repository exists
|
|
84
|
+
#
|
|
85
|
+
# @return [Boolean] true if current directory is a git repository
|
|
86
|
+
def git_repository?
|
|
87
|
+
Ace::Git::Atoms::CommandExecutor.in_git_repo?
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Get current git branch name or commit SHA if in detached HEAD state
|
|
91
|
+
#
|
|
92
|
+
# @return [String, nil] Current branch name, commit SHA (if detached), or nil on error
|
|
93
|
+
def current_branch
|
|
94
|
+
# ace-git's current_branch now handles detached HEAD state
|
|
95
|
+
# and returns SHA directly when detached
|
|
96
|
+
Ace::Git::Atoms::CommandExecutor.current_branch
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Check if a git ref (branch, tag, commit SHA) exists
|
|
100
|
+
#
|
|
101
|
+
# @param ref [String] Git ref to validate
|
|
102
|
+
# @return [Boolean] true if ref exists
|
|
103
|
+
def ref_exists?(ref)
|
|
104
|
+
result = execute("rev-parse", "--verify", "--quiet", ref, timeout: 5)
|
|
105
|
+
result[:success]
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Get git repository root directory
|
|
109
|
+
#
|
|
110
|
+
# Delegates to ace-git's CommandExecutor for repository root detection
|
|
111
|
+
#
|
|
112
|
+
# @return [String, nil] Path to git repository root or nil if not in a git repo
|
|
113
|
+
def git_root
|
|
114
|
+
Ace::Git::Atoms::CommandExecutor.repo_root
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|