@gw-tools/gw 0.11.0 → 0.12.2

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.
Files changed (2) hide show
  1. package/README.md +89 -16
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -163,7 +163,13 @@ gw init --root /path/to/your/repo.git
163
163
  ".env",
164
164
  "components/agents/.env",
165
165
  "components/ui/.vercel/"
166
- ]
166
+ ],
167
+ "hooks": {
168
+ "add": {
169
+ "pre": ["echo 'Creating worktree: {worktree}'"],
170
+ "post": ["pnpm install", "echo 'Setup complete!'"]
171
+ }
172
+ }
167
173
  }
168
174
  ```
169
175
 
@@ -172,6 +178,9 @@ gw init --root /path/to/your/repo.git
172
178
  - **root**: Absolute path to the git repository root (automatically detected or manually set with `gw init`)
173
179
  - **defaultBranch**: Default source worktree name (optional, defaults to "main")
174
180
  - **autoCopyFiles**: Array of file/directory paths to automatically copy when creating worktrees with `gw add` (optional, only set via `gw init --auto-copy-files`)
181
+ - **hooks**: Command hooks configuration (optional, set via `gw init --pre-add` and `--post-add`)
182
+ - **hooks.add.pre**: Array of commands to run before creating a worktree
183
+ - **hooks.add.post**: Array of commands to run after creating a worktree
175
184
 
176
185
  ## Commands
177
186
 
@@ -221,7 +230,7 @@ gw add feat/bugfix -f
221
230
  To enable automatic file copying, configure `autoCopyFiles` using `gw init`:
222
231
 
223
232
  ```bash
224
- gw init --root /path/to/repo.git --auto-copy-files .env,secrets/,components/ui/.vercel/
233
+ gw init --auto-copy-files .env,secrets/,components/ui/.vercel/
225
234
  ```
226
235
 
227
236
  This creates:
@@ -235,6 +244,45 @@ This creates:
235
244
 
236
245
  Now every time you run `gw add`, these files will be automatically copied from your default source worktree (usually `main`) to the new worktree.
237
246
 
247
+ #### Hooks
248
+
249
+ You can configure pre-add and post-add hooks to run commands before and after worktree creation. This is useful for:
250
+ - **Pre-add hooks**: Running validation scripts, checking prerequisites
251
+ - **Post-add hooks**: Installing dependencies, setting up the environment
252
+
253
+ ```bash
254
+ # Configure a post-add hook to install dependencies
255
+ gw init --post-add "pnpm install"
256
+
257
+ # Configure multiple hooks
258
+ gw init --pre-add "echo 'Creating: {worktree}'" --post-add "pnpm install" --post-add "echo 'Done!'"
259
+ ```
260
+
261
+ **Hook Variables:**
262
+
263
+ Hooks support variable substitution:
264
+ - `{worktree}` - The worktree name (e.g., "feat/new-feature")
265
+ - `{worktreePath}` - Full absolute path to the worktree
266
+ - `{gitRoot}` - The git repository root path
267
+ - `{branch}` - The branch name
268
+
269
+ **Hook Behavior:**
270
+ - **Pre-add hooks** run before the worktree is created (in the git root directory). If any pre-add hook fails, the worktree creation is aborted.
271
+ - **Post-add hooks** run after the worktree is created and files are copied (in the new worktree directory). If a post-add hook fails, a warning is shown but the worktree creation is considered successful.
272
+
273
+ **Example: Auto-install dependencies**
274
+
275
+ ```bash
276
+ # One-time setup
277
+ gw init --auto-copy-files .env --post-add "pnpm install"
278
+
279
+ # Now when you create a worktree:
280
+ gw add feat/new-feature
281
+ # 1. Creates the worktree
282
+ # 2. Copies .env file
283
+ # 3. Runs pnpm install in the new worktree
284
+ ```
285
+
238
286
  ### cd
239
287
 
240
288
  Navigate directly to a worktree by name or partial match. The command uses smart matching to find worktrees, searching both branch names and worktree paths.
@@ -348,44 +396,69 @@ gw root
348
396
 
349
397
  ### init
350
398
 
351
- Initialize gw configuration for a git repository. This command is only needed if auto-detection fails or if you want to manually specify the repository root.
399
+ Initialize gw configuration for a git repository. This command creates or updates the `.gw/config.json` file with your settings.
352
400
 
353
401
  ```bash
354
- gw init --root <path> [options]
402
+ gw init [options]
355
403
  ```
356
404
 
357
405
  #### Options
358
406
 
359
- - `--root <path>`: Specify the git repository root path (required)
407
+ - `--root <path>`: Specify the git repository root path (optional, auto-detects if not provided)
360
408
  - `--default-source <name>`: Set the default source worktree (default: "main")
361
409
  - `--auto-copy-files <files>`: Comma-separated list of files to auto-copy when creating worktrees with `gw add`
410
+ - `--pre-add <command>`: Command to run before `gw add` creates a worktree (can be specified multiple times)
411
+ - `--post-add <command>`: Command to run after `gw add` creates a worktree (can be specified multiple times)
362
412
  - `-h, --help`: Show help message
363
413
 
364
414
  #### Examples
365
415
 
366
416
  ```bash
367
- # Initialize with repository root
368
- gw init --root /Users/username/Workspace/my-project.git
417
+ # Initialize with auto-detected root
418
+ gw init
419
+
420
+ # Initialize with auto-copy files
421
+ gw init --auto-copy-files .env,secrets/
422
+
423
+ # Initialize with post-add hook to install dependencies
424
+ gw init --post-add "pnpm install"
425
+
426
+ # Initialize with pre-add validation hook
427
+ gw init --pre-add "echo 'Creating worktree: {worktree}'"
428
+
429
+ # Initialize with multiple hooks
430
+ gw init --pre-add "echo 'Starting...'" --post-add "pnpm install" --post-add "echo 'Done!'"
369
431
 
370
432
  # Initialize with custom default source
371
- gw init --root /Users/username/Workspace/my-project.git --default-source master
433
+ gw init --default-source master
372
434
 
373
- # Initialize with auto-copy files
374
- gw init --root /Users/username/Workspace/my-project.git --auto-copy-files .env,secrets/,components/ui/.vercel/
435
+ # Initialize with explicit repository root
436
+ gw init --root /Users/username/Workspace/my-project.git
437
+
438
+ # Full configuration example
439
+ gw init --auto-copy-files .env,secrets/ --post-add "pnpm install"
375
440
 
376
441
  # Show help
377
442
  gw init --help
378
443
  ```
379
444
 
380
- #### When to Use
445
+ #### Hook Variables
446
+
447
+ Hooks support variable substitution:
448
+ - `{worktree}` - The worktree name (e.g., "feat/new-feature")
449
+ - `{worktreePath}` - Full absolute path to the worktree
450
+ - `{gitRoot}` - The git repository root path
451
+ - `{branch}` - The branch name
381
452
 
382
- In most cases, you won't need to run `gw init` manually because the tool auto-detects your repository root on first run. However, you may need it when:
453
+ #### When to Use
383
454
 
384
- - Auto-detection fails (rare edge cases with non-standard repository structures)
385
- - You want to override the auto-detected root
386
- - You're setting up configuration before the repository has standard git structures
455
+ Use `gw init` to:
456
+ - Configure auto-copy files for automatic file copying on worktree creation
457
+ - Set up pre-add and post-add hooks for automation
458
+ - Override the auto-detected repository root (rare)
459
+ - Change the default source worktree from "main" to something else
387
460
 
388
- The config file is created at `.gw/config.json` in your current directory, so you can run this command from wherever makes sense for your workflow (typically the repository root).
461
+ The config file is created at `.gw/config.json` at the git root, so it's shared across all worktrees.
389
462
 
390
463
  ### sync
391
464
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gw-tools/gw",
3
- "version": "0.11.0",
3
+ "version": "0.12.2",
4
4
  "description": "A command-line tool for managing git worktrees - copy files between worktrees with ease",
5
5
  "keywords": [
6
6
  "git",