@gw-tools/gw 0.12.7 → 0.12.9

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 +67 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -169,7 +169,8 @@ gw init --root /path/to/your/repo.git
169
169
  "pre": ["echo 'Creating worktree: {worktree}'"],
170
170
  "post": ["pnpm install", "echo 'Setup complete!'"]
171
171
  }
172
- }
172
+ },
173
+ "cleanThreshold": 7
173
174
  }
174
175
  ```
175
176
 
@@ -181,6 +182,7 @@ gw init --root /path/to/your/repo.git
181
182
  - **hooks**: Command hooks configuration (optional, set via `gw init --pre-add` and `--post-add`)
182
183
  - **hooks.add.pre**: Array of commands to run before creating a worktree
183
184
  - **hooks.add.post**: Array of commands to run after creating a worktree
185
+ - **cleanThreshold**: Number of days before worktrees are considered stale for `gw clean` (optional, defaults to 7, set via `gw init --clean-threshold`)
184
186
 
185
187
  ## Commands
186
188
 
@@ -504,6 +506,70 @@ gw sync --dry-run feat-branch .env
504
506
  gw sync /full/path/to/repo/feat-branch .env
505
507
  ```
506
508
 
509
+ ### clean
510
+
511
+ Remove stale worktrees that are older than a configured threshold. By default, only removes worktrees with no uncommitted changes and no unpushed commits.
512
+
513
+ ```bash
514
+ gw clean [options]
515
+ ```
516
+
517
+ #### Options
518
+
519
+ - `-f, --force`: Skip safety checks (uncommitted changes, unpushed commits). WARNING: This may result in data loss
520
+ - `-n, --dry-run`: Preview what would be removed without actually removing
521
+ - `-h, --help`: Show help message
522
+
523
+ #### Examples
524
+
525
+ ```bash
526
+ # Preview stale worktrees (safe to run)
527
+ gw clean --dry-run
528
+
529
+ # Remove stale worktrees with safety checks
530
+ gw clean
531
+
532
+ # Force remove without safety checks (dangerous!)
533
+ gw clean --force
534
+
535
+ # Configure threshold during init
536
+ gw init --clean-threshold 14
537
+ ```
538
+
539
+ #### How It Works
540
+
541
+ The clean command:
542
+ 1. Checks for worktrees older than the configured threshold (default: 7 days)
543
+ 2. Verifies they have no uncommitted changes (unless `--force`)
544
+ 3. Verifies they have no unpushed commits (unless `--force`)
545
+ 4. Prompts for confirmation before deleting (unless `--dry-run`)
546
+ 5. Never removes bare/main repository worktrees
547
+
548
+ **Safety Features:**
549
+ - By default, only removes worktrees with NO uncommitted changes
550
+ - By default, only removes worktrees with NO unpushed commits
551
+ - Always prompts for confirmation before deletion
552
+ - Main/bare repository worktrees are never removed
553
+ - Use `--force` to bypass safety checks (use with caution)
554
+
555
+ **Configuration:**
556
+
557
+ The age threshold is stored in `.gw/config.json` and can be set during initialization:
558
+
559
+ ```bash
560
+ # Set clean threshold to 14 days
561
+ gw init --clean-threshold 14
562
+ ```
563
+
564
+ This creates/updates the config:
565
+ ```json
566
+ {
567
+ "root": "/path/to/repo.git",
568
+ "defaultBranch": "main",
569
+ "cleanThreshold": 14
570
+ }
571
+ ```
572
+
507
573
  ### Git Worktree Proxy Commands
508
574
 
509
575
  These commands wrap native `git worktree` operations, providing consistent colored output and help messages. All git flags and options are passed through transparently.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gw-tools/gw",
3
- "version": "0.12.7",
3
+ "version": "0.12.9",
4
4
  "description": "A command-line tool for managing git worktrees - copy files between worktrees with ease",
5
5
  "keywords": [
6
6
  "git",