ofsht 0.1.6

Git worktree management tool
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
# ofsht Manual Testing Procedures

This document describes the procedures for manually verifying each feature of ofsht.

> [!NOTE]
> **Path Display Conventions:**
> - ofsht displays paths under the home directory using `~` notation
> - This document uses `/tmp` for testing, so examples show absolute paths
> - When testing under your home directory, paths will display as `~/demo-ofsht-worktrees/...`

## Prerequisites

- Rust and cargo installed
- Git installed
- (Optional) zoxide installed

## Build

```bash
# Release build
cargo build --release

# Binary path after build
# target/release/ofsht
```

## Basic Functionality Verification

### 1. Prepare Test Repository

```bash
cd /tmp
rm -rf demo-ofsht
mkdir demo-ofsht
cd demo-ofsht
git init
git commit --allow-empty -m "Initial commit"
```

### 2. Create Worktree (`ofsht add`)

#### 2-1. Basic Creation (from HEAD)

```bash
# Create new worktree from HEAD
ofsht add feature-awesome

# Expected output:
# Created worktree at: /private/tmp/demo-ofsht-worktrees/feature-awesome
```

Verify created directory:

```bash
ls -la ../demo-ofsht-worktrees/feature-awesome
```

#### 2-2. Create with Start Point Branch

First, create a test branch:

```bash
cd /tmp/demo-ofsht
git checkout -b develop
echo "develop branch" > develop.txt
git add develop.txt
git commit -m "Add develop.txt"
git checkout main
```

Create worktree with start point:

```bash
# Create new feature branch from develop branch
ofsht add feature-from-develop develop

# Expected output:
# Created worktree at: /private/tmp/demo-ofsht-worktrees/feature-from-develop

# Verify: develop.txt should exist
ls ../demo-ofsht-worktrees/feature-from-develop/
cat ../demo-ofsht-worktrees/feature-from-develop/develop.txt
```

#### 2-3. Create from Remote Branch

```bash
# Assuming remote branch (use local branch as substitute for testing)
ofsht add feature-from-remote origin/main
# Or from local branch:
ofsht add feature-from-local main
```

#### 2-4. Create from Tag

```bash
# Create tag
cd /tmp/demo-ofsht
git tag v1.0.0
git checkout main

# Create worktree from tag
ofsht add release-prep v1.0.0

# Verify
cd ../demo-ofsht-worktrees/release-prep
git log --oneline -1
```

#### 2-5. Create from Relative Commit

```bash
# Create from 3 commits before HEAD
ofsht add feature-old-commit HEAD~3

# Or from specific commit hash
# ofsht add feature-specific abc123
```

#### 2-6. Error Case: Non-existent Branch

```bash
# Specify non-existent branch
ofsht add feature-invalid does-not-exist

# Expected behavior:
# Git error message is displayed
# Error: git worktree add failed: ...
```

#### 2-7. Execute from Within Worktree (Verify Repository Root Resolution)

```bash
# Move to first worktree
cd ../demo-ofsht-worktrees/feature-awesome

# Create new worktree from within this worktree
ofsht add feature-from-worktree

# Expected behavior:
# Relative path is resolved from main repository root, so
# created at ../demo-ofsht-worktrees/feature-from-worktree

# Verify
ls -la ../feature-from-worktree

# Return to main repository
cd /tmp/demo-ofsht
```

### 3. List Worktrees (`ofsht ls`)

```bash
ofsht ls

# Expected output:
# /private/tmp/demo-ofsht                            <commit> [main]
# /private/tmp/demo-ofsht-worktrees/feature-awesome  <commit> [feature-awesome]
```

### 4. Navigate to Worktree (`ofsht cd`)

```bash
# Get worktree path
ofsht cd feature-awesome

# Expected output:
# /private/tmp/demo-ofsht-worktrees/feature-awesome

# To actually navigate
cd $(ofsht cd feature-awesome)
pwd
```

### 5. Remove Worktree (`ofsht rm`)

Create another worktree before removing:

```bash
# Create worktree for deletion
ofsht add test-delete

# Remove worktree
ofsht rm /private/tmp/demo-ofsht-worktrees/test-delete

# Expected output:
# Removed worktree: /private/tmp/demo-ofsht-worktrees/test-delete
# Deleted branch: test-delete

# Verify
ofsht ls
```

### 6. Remove Prunable Worktree

Test removing worktrees whose directories have been manually deleted (prunable state).
When a worktree directory is deleted manually, Git marks it as "prunable" and `ofsht rm` can still remove it:

```bash
# Create a worktree
ofsht add test-prunable

# Manually delete the worktree directory to make it prunable
rm -rf ../demo-ofsht-worktrees/test-prunable

# Verify it's shown as prunable (use --porcelain for clear output)
git worktree list --porcelain
# Expected: Shows a line containing "prunable" after the test-prunable entry

# Remove by branch name
ofsht rm test-prunable
# Expected output:
# Removed worktree: /path/to/demo-ofsht-worktrees/test-prunable
# Deleted branch: test-prunable

# Verify removal
git worktree list --porcelain | grep test-prunable
# Expected: No output (entry removed)
git branch --list test-prunable
# Expected: Empty (branch deleted)

# Test with absolute path
ofsht add test-prunable-abs
rm -rf ../demo-ofsht-worktrees/test-prunable-abs
# Get absolute path
ABS_PATH=$(cd ../demo-ofsht-worktrees && pwd)/test-prunable-abs
ofsht rm "$ABS_PATH"
# Expected output:
# Removed worktree: /path/to/demo-ofsht-worktrees/test-prunable-abs
# Deleted branch: test-prunable-abs

# Verify removal
git worktree list --porcelain | grep test-prunable-abs
# Expected: No output
git branch --list test-prunable-abs
# Expected: Empty

# Test with relative path
ofsht add test-prunable-rel
rm -rf ../demo-ofsht-worktrees/test-prunable-rel
ofsht rm ../demo-ofsht-worktrees/test-prunable-rel
# Expected output:
# Removed worktree: /path/to/demo-ofsht-worktrees/test-prunable-rel
# Deleted branch: test-prunable-rel

# Verify removal
git worktree list --porcelain | grep test-prunable-rel
# Expected: No output
git branch --list test-prunable-rel
# Expected: Empty

# Final verification - all prunable worktrees should be removed
git worktree list
# Expected: Only shows main worktree and any other active worktrees
```

## Hook Functionality Verification

### 1. Create Configuration File

```bash
cd /tmp/demo-ofsht

cat > .ofsht.toml << 'EOF'
[hooks.create]
run = ["echo 'Hello from create hook!'", "pwd"]
copy = []
link = {}

[hooks.delete]
run = ["echo 'Goodbye from delete hook!'"]

[worktree]
dir = "../{repo}-worktrees/{branch}"
EOF
```

### 2. Verify Create Hook

```bash
ofsht add feature-with-hooks

# Expected output:
# Created worktree at: /private/tmp/demo-ofsht-worktrees/feature-with-hooks
# Executing create hooks...
# Hello from create hook!
# /private/tmp/demo-ofsht-worktrees/feature-with-hooks
```

### 3. Verify Copy and Link

```bash
# Create test file
echo "test config" > .testrc

cat > .ofsht.toml << 'EOF'
[hooks.create]
run = []
copy = [".testrc"]
link = { ".testrc" = ".testrc-link" }

[worktree]
dir = "../{repo}-worktrees/{branch}"
EOF

# Create worktree
ofsht add feature-copy-link

# Verify copied file
cat ../demo-ofsht-worktrees/feature-copy-link/.testrc

# Verify symlink
ls -la ../demo-ofsht-worktrees/feature-copy-link/.testrc-link
cat ../demo-ofsht-worktrees/feature-copy-link/.testrc-link
```

### 4. Verify Delete Hook

```bash
cat > .ofsht.toml << 'EOF'
[hooks.delete]
run = ["echo 'Cleaning up...'", "ls -la"]
EOF

ofsht rm /private/tmp/demo-ofsht-worktrees/feature-copy-link

# Expected output:
# Executing delete hooks...
# Cleaning up...
# (directory listing)
# Removed worktree: /private/tmp/demo-ofsht-worktrees/feature-copy-link
# Deleted branch: feature-copy-link
```

## zoxide Integration Verification

### Verify Prerequisites

```bash
# Check if zoxide is installed
zoxide --version

# If not installed:
# macOS: brew install zoxide
# Linux: curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | bash
```

### 1. Verify with zoxide Enabled (Default)

```bash
cd /tmp/demo-ofsht

# Remove config file (use default settings)
rm -f .ofsht.toml

# Create worktree
ofsht add feature-with-zoxide

# Verify registration in zoxide
zoxide query feature-with-zoxide

# Expected output:
# /private/tmp/demo-ofsht-worktrees/feature-with-zoxide
```

### 2. Verify with zoxide Disabled

```bash
# Create config file to disable zoxide
cat > .ofsht.toml << 'EOF'
[zoxide]
enabled = false
EOF

# Create worktree
ofsht add feature-no-zoxide

# Verify not registered in zoxide
zoxide query feature-no-zoxide 2>&1 || echo "✅ Not registered in zoxide (as expected)"

# Expected output:
# zoxide: no match found
# ✅ Not registered in zoxide (as expected)
```

### 3. Practical Workflow with zoxide

```bash
# Remove config file (re-enable zoxide)
rm -f .ofsht.toml

# Create new worktree
ofsht add feature-user-auth

# Navigate quickly with zoxide
z feature-user-auth
pwd

# Expected output:
# /private/tmp/demo-ofsht-worktrees/feature-user-auth
```

## Path Template Customization Verification

### Configure Custom Path Template

```bash
cd /tmp/demo-ofsht

cat > .ofsht.toml << 'EOF'
[worktree]
dir = "/tmp/custom-worktrees/{repo}/{branch}"
EOF

# Create worktree with custom path
ofsht add feature-custom-path

# Verify
ls -la /tmp/custom-worktrees/demo-ofsht/feature-custom-path
ofsht ls

# Cleanup
rm -rf /tmp/custom-worktrees
```

## Global Configuration Verification

### Create Global Configuration File

```bash
# Create global config directory
mkdir -p ~/.config/ofsht

cat > ~/.config/ofsht/config.toml << 'EOF'
[worktree]
dir = "~/worktrees/{repo}/{branch}"

[zoxide]
enabled = true

[hooks.create]
run = ["echo 'Global hook executed!'"]
EOF
```

### Verify Local Configuration Priority

```bash
cd /tmp/demo-ofsht

# Without local config, global config is used
rm -f .ofsht.toml
ofsht add feature-global

# Expected output includes "Global hook executed!"

# Create local config
cat > .ofsht.toml << 'EOF'
[hooks.create]
run = ["echo 'Local hook executed!'"]
EOF

# Local config takes priority
ofsht add feature-local

# Expected output includes "Local hook executed!"
# "Global hook executed!" is not executed
```

## Cleanup

After verification is complete, clean up test directories:

```bash
# Remove test directories
rm -rf /tmp/demo-ofsht
rm -rf /tmp/demo-ofsht-worktrees
rm -rf ~/demo-ofsht-worktrees

# Remove global config (if needed)
rm -rf ~/.config/ofsht
```

## Troubleshooting

### Worktree Creation Fails

```bash
# Verify it's a Git repository
git status

# Check if branch already exists
git branch -a
```

### Not Registered in zoxide

```bash
# Check if zoxide is installed
which zoxide

# Verify zoxide is enabled in config file
cat .ofsht.toml
```

### Hooks Not Executing

```bash
# Verify config file syntax
cat .ofsht.toml

# Check if command exists in PATH
which <command>
```

## Summary

This document verified the following features:

- ✅ Basic operations (add, ls, cd, rm)
- ✅ Hook functionality (create, delete)
- ✅ File copying and symlink creation
- ✅ zoxide integration
- ✅ Path template customization
- ✅ Local/global configuration

All features can be verified to work as expected.