You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Expected: Creates /tmp/gtr-pre-removed and /tmp/gtr-removed files
180
+
181
+
# Test pre-remove hook failure aborts removal
182
+
git config gtr.hook.preRemove "exit 1"
183
+
./bin/gtr new test-hook-fail
184
+
./bin/gtr rm test-hook-fail
185
+
# Expected: Removal aborted due to hook failure
186
+
./bin/gtr rm test-hook-fail --force
187
+
# Expected: Removal proceeds despite hook failure
179
188
```
180
189
181
190
### Debugging Bash Scripts
@@ -440,6 +449,7 @@ All config keys use `gtr.*` prefix and are managed via `git config`. Configurati
440
449
-`gtr.copy.includeDirs`: Multi-valued directory patterns to copy (e.g., "node_modules", ".venv", "vendor")
441
450
-`gtr.copy.excludeDirs`: Multi-valued directory patterns to exclude when copying (supports globs like "node_modules/.cache", "\*/.cache")
442
451
-`gtr.hook.postCreate`: Multi-valued commands to run after creating worktree
452
+
-`gtr.hook.preRemove`: Multi-valued commands to run before removing worktree (abort on failure unless --force)
443
453
-`gtr.hook.postRemove`: Multi-valued commands to run after removing worktree
444
454
445
455
### File-based Configuration
@@ -456,6 +466,7 @@ All config keys use `gtr.*` prefix and are managed via `git config`. Configurati
456
466
|`gtr.copy.includeDirs`|`copy.includeDirs`|
457
467
|`gtr.copy.excludeDirs`|`copy.excludeDirs`|
458
468
|`gtr.hook.postCreate`|`hooks.postCreate`|
469
+
|`gtr.hook.preRemove`|`hooks.preRemove`|
459
470
|`gtr.hook.postRemove`|`hooks.postRemove`|
460
471
|`gtr.editor.default`|`defaults.editor`|
461
472
|`gtr.ai.default`|`defaults.ai`|
@@ -471,12 +482,14 @@ All config keys use `gtr.*` prefix and are managed via `git config`. Configurati
471
482
-`GTR_AI_CMD`: Generic AI tool command for custom tools without adapter files
472
483
-`GTR_AI_CMD_NAME`: First word of `GTR_AI_CMD` used for availability checks
473
484
474
-
**Hook environment variables** (available in `gtr.hook.postCreate` and `gtr.hook.postRemove` scripts):
485
+
**Hook environment variables** (available in `gtr.hook.postCreate`, `gtr.hook.preRemove`, and `gtr.hook.postRemove` scripts):
475
486
476
487
-`REPO_ROOT`: Repository root path
477
-
-`WORKTREE_PATH`: New worktree path
488
+
-`WORKTREE_PATH`: Worktree path
478
489
-`BRANCH`: Branch name
479
490
491
+
**Note:**`preRemove` hooks run with cwd set to the worktree directory (before deletion). If a preRemove hook fails, removal is aborted unless `--force` is used.
492
+
480
493
## Important Implementation Details
481
494
482
495
**Worktree Path Resolution**: The `resolve_target()` function in `lib/core.sh` handles both branch names and the special ID '1'. It checks in order: special ID, current branch in main repo, sanitized path match, full directory scan. Returns tab-separated format: `is_main\tpath\tbranch`.
@@ -493,7 +506,7 @@ All config keys use `gtr.*` prefix and are managed via `git config`. Configurati
493
506
494
507
**Configuration Precedence**: The `cfg_default()` function in `lib/config.sh` checks local git config first, then `.gtrconfig` file, then global/system git config, then environment variables, then fallback values. Use `cfg_get_all(key, file_key, scope)` for multi-valued configs where `file_key` is the corresponding key in `.gtrconfig` (e.g., `copy.include` for `gtr.copy.include`).
495
508
496
-
**Multi-Value Configuration Pattern**: Some configs support multiple values (`gtr.copy.include`, `gtr.copy.exclude`, `gtr.copy.includeDirs`, `gtr.copy.excludeDirs`, `gtr.hook.postCreate`, `gtr.hook.postRemove`). The `cfg_get_all()` function merges values from local + global + system + `.gtrconfig` file and deduplicates. Set with: `git config --add gtr.copy.include "pattern"`.
509
+
**Multi-Value Configuration Pattern**: Some configs support multiple values (`gtr.copy.include`, `gtr.copy.exclude`, `gtr.copy.includeDirs`, `gtr.copy.excludeDirs`, `gtr.hook.postCreate`, `gtr.hook.preRemove`, `gtr.hook.postRemove`). The `cfg_get_all()` function merges values from local + global + system + `.gtrconfig` file and deduplicates. Set with: `git config --add gtr.copy.include "pattern"`.
497
510
498
511
**Adapter Loading**: Adapters are sourced dynamically via `load_editor_adapter()` and `load_ai_adapter()` in `bin/gtr`. They must exist in `adapters/editor/` or `adapters/ai/` and define the required functions.
0 commit comments