@gw-tools/gw 0.12.11 → 0.12.15

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 +117 -9
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -25,24 +25,28 @@ A command-line tool for managing git worktrees, built with Deno.
25
25
  - [Arguments](#arguments-1)
26
26
  - [Examples](#examples-1)
27
27
  - [How It Works](#how-it-works)
28
- - [install-shell](#install-shell)
28
+ - [pull](#pull)
29
29
  - [Options](#options-1)
30
30
  - [Examples](#examples-2)
31
- - [root](#root)
32
- - [Examples](#examples-3)
33
31
  - [How It Works](#how-it-works-1)
34
- - [init](#init)
32
+ - [install-shell](#install-shell)
35
33
  - [Options](#options-2)
34
+ - [Examples](#examples-3)
35
+ - [root](#root)
36
36
  - [Examples](#examples-4)
37
+ - [How It Works](#how-it-works-2)
38
+ - [init](#init)
39
+ - [Options](#options-3)
40
+ - [Examples](#examples-5)
37
41
  - [When to Use](#when-to-use)
38
42
  - [sync](#sync)
39
43
  - [Arguments](#arguments-2)
40
- - [Options](#options-3)
41
- - [Examples](#examples-5)
42
- - [clean](#clean)
43
44
  - [Options](#options-4)
44
45
  - [Examples](#examples-6)
45
- - [How It Works](#how-it-works-2)
46
+ - [clean](#clean)
47
+ - [Options](#options-5)
48
+ - [Examples](#examples-7)
49
+ - [How It Works](#how-it-works-3)
46
50
  - [Git Worktree Proxy Commands](#git-worktree-proxy-commands)
47
51
  - [list (ls)](#list-ls)
48
52
  - [remove (rm)](#remove-rm)
@@ -174,7 +178,9 @@ gw init --root /path/to/your/repo.git
174
178
  "post": ["pnpm install", "echo 'Setup complete!'"]
175
179
  }
176
180
  },
177
- "cleanThreshold": 7
181
+ "cleanThreshold": 7,
182
+ "autoClean": true,
183
+ "lastAutoCleanTime": 1706371200000
178
184
  }
179
185
  ```
180
186
 
@@ -189,6 +195,8 @@ gw init --root /path/to/your/repo.git
189
195
  - **hooks.add.pre**: Array of commands to run before creating a worktree
190
196
  - **hooks.add.post**: Array of commands to run after creating a worktree
191
197
  - **cleanThreshold**: Number of days before worktrees are considered stale for `gw clean` (optional, defaults to 7, set via `gw init --clean-threshold`)
198
+ - **autoClean**: Automatically remove stale worktrees when running `gw add` or `gw list` (optional, defaults to false, set via `gw init --auto-clean`)
199
+ - **lastAutoCleanTime**: Internal timestamp tracking last auto-cleanup run (managed automatically, do not edit manually)
192
200
 
193
201
  ## Commands
194
202
 
@@ -205,6 +213,12 @@ This command wraps `git worktree add` and optionally copies files to the new wor
205
213
  **Branch Creation Behavior:**
206
214
  When creating a new worktree without specifying an existing branch, `gw add` automatically fetches the latest version of your default branch (e.g., `main`) from the remote (e.g., `origin/main`) to ensure your new branch is based on the most recent code. If the remote is unavailable (no network or no remote configured), it gracefully falls back to using the local branch with a warning message.
207
215
 
216
+ **Upstream Tracking:**
217
+ When `gw add` creates a new branch, it automatically configures the branch to track `origin/<branch-name>` (e.g., `origin/feat/my-feature`). This means `git push` will push to the correct remote branch without needing to specify `-u origin <branch>` on first push.
218
+
219
+ **Git Ref Conflict Detection:**
220
+ The command automatically detects and prevents Git ref naming conflicts. For example, you cannot have both a branch named `test` and `test/foo` because Git stores branches as files in `.git/refs/heads/`, and `test` cannot be both a file and a directory. If a conflict is detected, you'll receive a helpful error message with suggestions for resolving it.
221
+
208
222
  #### Arguments
209
223
 
210
224
  - `<worktree-name>`: Name or path for the new worktree
@@ -332,6 +346,67 @@ The `cd` command integrates with your shell through an automatically installed f
332
346
 
333
347
  **Note**: Shell integration is automatically installed when you install via npm. If needed, you can manually install or remove it using `gw install-shell`.
334
348
 
349
+ ### pull
350
+
351
+ Merge the latest version of the default branch (or specified branch) into your current worktree. This is useful when you want to update your feature branch with the latest changes from main without having to switch worktrees.
352
+
353
+ ```bash
354
+ gw pull [options]
355
+ ```
356
+
357
+ When working in a worktree, you cannot easily checkout main to pull the latest changes because main is typically checked out in another worktree. The `gw pull` command solves this by fetching the latest version of the default branch and merging it into your current branch.
358
+
359
+ #### Options
360
+
361
+ - `--from <branch>`: Merge from specified branch instead of defaultBranch (e.g., `--from develop`)
362
+ - `--remote <name>`: Specify remote name (default: "origin")
363
+ - `-f, --force`: Skip uncommitted changes check (not recommended)
364
+ - `-n, --dry-run`: Preview what would happen without executing
365
+ - `-h, --help`: Show help message
366
+
367
+ #### Examples
368
+
369
+ ```bash
370
+ # Merge latest default branch (typically main)
371
+ gw pull
372
+
373
+ # Merge from a specific branch
374
+ gw pull --from develop
375
+
376
+ # Preview what would happen
377
+ gw pull --dry-run
378
+
379
+ # Force pull even with uncommitted changes (not recommended)
380
+ gw pull --force
381
+
382
+ # Use a different remote
383
+ gw pull --remote upstream
384
+ ```
385
+
386
+ #### How It Works
387
+
388
+ 1. Fetches the latest version of the target branch from remote (e.g., `origin/main`)
389
+ 2. Merges it into your current worktree's active branch
390
+ 3. Creates merge commit if histories have diverged
391
+
392
+ **Safety checks:**
393
+ - Blocks if you have uncommitted changes (use `--force` to override)
394
+ - Blocks if you're in a detached HEAD state
395
+ - Handles merge conflicts gracefully with clear guidance
396
+
397
+ **Merge strategy:** Allows merge commits (not fast-forward only), so it works even if you have local commits.
398
+
399
+ **Configuration:**
400
+
401
+ The default branch is read from `.gw/config.json`:
402
+ ```json
403
+ {
404
+ "defaultBranch": "main"
405
+ }
406
+ ```
407
+
408
+ If not configured, defaults to "main".
409
+
335
410
  ### install-shell
336
411
 
337
412
  Install or remove shell integration for the `gw cd` command. This is automatically run during `npm install`, but can be run manually if needed.
@@ -421,6 +496,7 @@ gw init [options]
421
496
  - `--pre-add <command>`: Command to run before `gw add` creates a worktree (can be specified multiple times)
422
497
  - `--post-add <command>`: Command to run after `gw add` creates a worktree (can be specified multiple times)
423
498
  - `--clean-threshold <days>`: Number of days before worktrees are considered stale for `gw clean` (default: 7)
499
+ - `--auto-clean`: Enable automatic cleanup of stale worktrees (runs on `gw add` and `gw list` with 24-hour cooldown)
424
500
  - `-h, --help`: Show help message
425
501
 
426
502
  #### Examples
@@ -465,6 +541,33 @@ Hooks support variable substitution:
465
541
  - `{gitRoot}` - The git repository root path
466
542
  - `{branch}` - The branch name
467
543
 
544
+ #### Auto-Cleanup Configuration
545
+
546
+ Enable automatic removal of stale worktrees to keep your repository clean:
547
+
548
+ ```bash
549
+ # Enable auto-cleanup with default 7-day threshold
550
+ gw init --auto-clean
551
+
552
+ # Enable with custom threshold (14 days)
553
+ gw init --auto-clean --clean-threshold 14
554
+
555
+ # Enable with other options
556
+ gw init --auto-clean --auto-copy-files .env --post-add "pnpm install"
557
+ ```
558
+
559
+ **How it works:**
560
+ - Runs automatically on `gw add` and `gw list` commands
561
+ - Only runs once per 24 hours (cooldown)
562
+ - Removes worktrees older than `cleanThreshold` with:
563
+ - No uncommitted changes
564
+ - No staged files
565
+ - No unpushed commits
566
+ - Shows brief message only when worktrees are removed: `🧹 Auto-cleanup: Removed 2 stale worktrees`
567
+ - Never interrupts or fails the main command
568
+
569
+ This is an opt-in feature. Use `gw clean` for manual, interactive cleanup with more control.
570
+
468
571
  #### When to Use
469
572
 
470
573
  Use `gw init` to:
@@ -524,6 +627,8 @@ gw sync /full/path/to/repo/feat-branch .env
524
627
 
525
628
  Remove stale worktrees that are older than a configured threshold. By default, only removes worktrees with no uncommitted changes and no unpushed commits.
526
629
 
630
+ **Note:** For automatic cleanup, see `gw init --auto-clean`. The `clean` command provides interactive, manual cleanup with detailed output and confirmation prompts.
631
+
527
632
  ```bash
528
633
  gw clean [options]
529
634
  ```
@@ -713,6 +818,9 @@ gw add feat-new-feature
713
818
  # Navigate to your new worktree
714
819
  gw cd feat-new-feature
715
820
 
821
+ # Keep your feature branch updated with latest changes from main
822
+ gw pull
823
+
716
824
  # Alternative: Create worktree and copy specific files
717
825
  gw add feat-bugfix .env custom-config.json
718
826
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gw-tools/gw",
3
- "version": "0.12.11",
3
+ "version": "0.12.15",
4
4
  "description": "A command-line tool for managing git worktrees - copy files between worktrees with ease",
5
5
  "keywords": [
6
6
  "git",