@camaradesuk/git-worktree-tools 1.0.3

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 (119) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +259 -0
  3. package/dist/cli/cleanpr.d.ts +13 -0
  4. package/dist/cli/cleanpr.d.ts.map +1 -0
  5. package/dist/cli/cleanpr.js +441 -0
  6. package/dist/cli/cleanpr.js.map +1 -0
  7. package/dist/cli/lswt.d.ts +11 -0
  8. package/dist/cli/lswt.d.ts.map +1 -0
  9. package/dist/cli/lswt.js +313 -0
  10. package/dist/cli/lswt.js.map +1 -0
  11. package/dist/cli/newpr.d.ts +11 -0
  12. package/dist/cli/newpr.d.ts.map +1 -0
  13. package/dist/cli/newpr.js +888 -0
  14. package/dist/cli/newpr.js.map +1 -0
  15. package/dist/cli/wtlink.d.ts +15 -0
  16. package/dist/cli/wtlink.d.ts.map +1 -0
  17. package/dist/cli/wtlink.js +124 -0
  18. package/dist/cli/wtlink.js.map +1 -0
  19. package/dist/e2e/cli.e2e.test.d.ts +2 -0
  20. package/dist/e2e/cli.e2e.test.d.ts.map +1 -0
  21. package/dist/e2e/cli.e2e.test.js +215 -0
  22. package/dist/e2e/cli.e2e.test.js.map +1 -0
  23. package/dist/index.d.ts +20 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +17 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/integration/git.integration.test.d.ts +2 -0
  28. package/dist/integration/git.integration.test.d.ts.map +1 -0
  29. package/dist/integration/git.integration.test.js +333 -0
  30. package/dist/integration/git.integration.test.js.map +1 -0
  31. package/dist/lib/colors.d.ts +59 -0
  32. package/dist/lib/colors.d.ts.map +1 -0
  33. package/dist/lib/colors.js +145 -0
  34. package/dist/lib/colors.js.map +1 -0
  35. package/dist/lib/colors.test.d.ts +2 -0
  36. package/dist/lib/colors.test.d.ts.map +1 -0
  37. package/dist/lib/colors.test.js +69 -0
  38. package/dist/lib/colors.test.js.map +1 -0
  39. package/dist/lib/config.d.ts +58 -0
  40. package/dist/lib/config.d.ts.map +1 -0
  41. package/dist/lib/config.js +91 -0
  42. package/dist/lib/config.js.map +1 -0
  43. package/dist/lib/config.test.d.ts +2 -0
  44. package/dist/lib/config.test.d.ts.map +1 -0
  45. package/dist/lib/config.test.js +84 -0
  46. package/dist/lib/config.test.js.map +1 -0
  47. package/dist/lib/constants.d.ts +37 -0
  48. package/dist/lib/constants.d.ts.map +1 -0
  49. package/dist/lib/constants.js +37 -0
  50. package/dist/lib/constants.js.map +1 -0
  51. package/dist/lib/errors.d.ts +88 -0
  52. package/dist/lib/errors.d.ts.map +1 -0
  53. package/dist/lib/errors.js +112 -0
  54. package/dist/lib/errors.js.map +1 -0
  55. package/dist/lib/errors.test.d.ts +2 -0
  56. package/dist/lib/errors.test.d.ts.map +1 -0
  57. package/dist/lib/errors.test.js +117 -0
  58. package/dist/lib/errors.test.js.map +1 -0
  59. package/dist/lib/git.d.ts +224 -0
  60. package/dist/lib/git.d.ts.map +1 -0
  61. package/dist/lib/git.js +524 -0
  62. package/dist/lib/git.js.map +1 -0
  63. package/dist/lib/git.test.d.ts +2 -0
  64. package/dist/lib/git.test.d.ts.map +1 -0
  65. package/dist/lib/git.test.js +402 -0
  66. package/dist/lib/git.test.js.map +1 -0
  67. package/dist/lib/github.d.ts +82 -0
  68. package/dist/lib/github.d.ts.map +1 -0
  69. package/dist/lib/github.js +254 -0
  70. package/dist/lib/github.js.map +1 -0
  71. package/dist/lib/github.test.d.ts +2 -0
  72. package/dist/lib/github.test.d.ts.map +1 -0
  73. package/dist/lib/github.test.js +258 -0
  74. package/dist/lib/github.test.js.map +1 -0
  75. package/dist/lib/prompts.d.ts +39 -0
  76. package/dist/lib/prompts.d.ts.map +1 -0
  77. package/dist/lib/prompts.js +213 -0
  78. package/dist/lib/prompts.js.map +1 -0
  79. package/dist/lib/prompts.test.d.ts +2 -0
  80. package/dist/lib/prompts.test.d.ts.map +1 -0
  81. package/dist/lib/prompts.test.js +250 -0
  82. package/dist/lib/prompts.test.js.map +1 -0
  83. package/dist/lib/state-detection.d.ts +65 -0
  84. package/dist/lib/state-detection.d.ts.map +1 -0
  85. package/dist/lib/state-detection.js +186 -0
  86. package/dist/lib/state-detection.js.map +1 -0
  87. package/dist/lib/state-detection.test.d.ts +2 -0
  88. package/dist/lib/state-detection.test.d.ts.map +1 -0
  89. package/dist/lib/state-detection.test.js +164 -0
  90. package/dist/lib/state-detection.test.js.map +1 -0
  91. package/dist/lib/wtlink/index.d.ts +5 -0
  92. package/dist/lib/wtlink/index.d.ts.map +1 -0
  93. package/dist/lib/wtlink/index.js +7 -0
  94. package/dist/lib/wtlink/index.js.map +1 -0
  95. package/dist/lib/wtlink/link-configs.d.ts +10 -0
  96. package/dist/lib/wtlink/link-configs.d.ts.map +1 -0
  97. package/dist/lib/wtlink/link-configs.js +411 -0
  98. package/dist/lib/wtlink/link-configs.js.map +1 -0
  99. package/dist/lib/wtlink/link-configs.test.d.ts +2 -0
  100. package/dist/lib/wtlink/link-configs.test.d.ts.map +1 -0
  101. package/dist/lib/wtlink/link-configs.test.js +179 -0
  102. package/dist/lib/wtlink/link-configs.test.js.map +1 -0
  103. package/dist/lib/wtlink/main-menu.d.ts +2 -0
  104. package/dist/lib/wtlink/main-menu.d.ts.map +1 -0
  105. package/dist/lib/wtlink/main-menu.js +149 -0
  106. package/dist/lib/wtlink/main-menu.js.map +1 -0
  107. package/dist/lib/wtlink/manage-manifest.d.ts +9 -0
  108. package/dist/lib/wtlink/manage-manifest.d.ts.map +1 -0
  109. package/dist/lib/wtlink/manage-manifest.js +1262 -0
  110. package/dist/lib/wtlink/manage-manifest.js.map +1 -0
  111. package/dist/lib/wtlink/validate-manifest.d.ts +6 -0
  112. package/dist/lib/wtlink/validate-manifest.d.ts.map +1 -0
  113. package/dist/lib/wtlink/validate-manifest.js +51 -0
  114. package/dist/lib/wtlink/validate-manifest.js.map +1 -0
  115. package/dist/lib/wtlink/validate-manifest.test.d.ts +2 -0
  116. package/dist/lib/wtlink/validate-manifest.test.d.ts.map +1 -0
  117. package/dist/lib/wtlink/validate-manifest.test.js +115 -0
  118. package/dist/lib/wtlink/validate-manifest.test.js.map +1 -0
  119. package/package.json +84 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 CAMARADES UK
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,259 @@
1
+ # git-worktree-tools
2
+
3
+ Cross-platform CLI tools for git worktree workflow management. Create PRs with dedicated worktrees, sync gitignored files, and manage your development workflow.
4
+
5
+ ## Features
6
+
7
+ - **Cross-platform**: Works natively on Windows, macOS, and Linux (no bash/WSL required)
8
+ - **Smart State Detection**: Intelligently handles 10+ git scenarios (uncommitted changes, local commits, existing branches, etc.)
9
+ - **PR + Worktree Workflow**: Create PRs and dedicated worktrees in one command
10
+ - **Shared Repos**: Automatically create worktrees in related repositories
11
+ - **Config Syncing**: Share gitignored config files (.env, .vscode, etc.) between worktrees via hard links
12
+ - **Configurable**: Per-repo settings via `.worktreerc`
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install -g @camaradesuk/git-worktree-tools
18
+ ```
19
+
20
+ **Prerequisites**:
21
+
22
+ - Node.js 18+
23
+ - Git
24
+ - GitHub CLI (`gh`) for PR operations
25
+
26
+ ## Quick Start
27
+
28
+ ```bash
29
+ # Create a new PR with worktree
30
+ newpr "Add user authentication feature"
31
+
32
+ # List all worktrees
33
+ lswt
34
+
35
+ # Clean up merged/closed PR worktrees
36
+ cleanpr
37
+
38
+ # Manage shared config files between worktrees
39
+ wtlink
40
+ ```
41
+
42
+ ## Commands
43
+
44
+ ### newpr
45
+
46
+ Create a new PR with an associated worktree.
47
+
48
+ ```bash
49
+ newpr "Description of the feature"
50
+ newpr --branch my-feature "Feature description"
51
+ newpr --pr 123 # Work on existing PR
52
+ newpr --draft "WIP feature"
53
+ ```
54
+
55
+ **Smart State Handling**: The tool detects your current git state and offers appropriate options:
56
+
57
+ - Uncommitted changes? Choose to commit, stash, or leave them
58
+ - Local commits on main? Include them or start fresh
59
+ - On a feature branch? Create PR for it or start new
60
+ - Detached HEAD? Create branch from current commit or main
61
+
62
+ ### cleanpr
63
+
64
+ Clean up worktrees for merged or closed PRs.
65
+
66
+ ```bash
67
+ cleanpr # Interactive cleanup
68
+ cleanpr --all # Clean all merged/closed automatically
69
+ cleanpr --force # Force remove even if not merged
70
+ ```
71
+
72
+ ### lswt
73
+
74
+ List all worktrees with status information.
75
+
76
+ ```bash
77
+ lswt # List all worktrees
78
+ lswt --status # Include PR status (open/merged/closed)
79
+ lswt --json # Output as JSON for scripting
80
+ lswt --verbose # Show more details (commit hashes, full paths)
81
+ ```
82
+
83
+ ### wtlink
84
+
85
+ Interactive CLI for managing configuration file links between git worktrees. Share config files while keeping build artifacts separate using hard links and a manifest file.
86
+
87
+ ```bash
88
+ wtlink # Interactive main menu
89
+ wtlink manage # Interactive file browser to select files to share
90
+ wtlink link # Create hard links based on manifest
91
+ wtlink link ../my-app.pr42 # Link to specific worktree
92
+ wtlink validate # Verify manifest integrity
93
+ ```
94
+
95
+ **Command options:**
96
+
97
+ ```bash
98
+ # manage - Discover and manage the manifest
99
+ wtlink manage # Interactive mode
100
+ wtlink manage --non-interactive # Auto-add new files as commented
101
+ wtlink manage --clean # Remove stale entries automatically
102
+ wtlink manage --dry-run # Preview changes without writing
103
+ wtlink manage --backup # Create .wtlinkrc.bak before updating
104
+
105
+ # link - Create links between worktrees
106
+ wtlink link [source] [dest] # Link from source to destination
107
+ wtlink link --dry-run # Preview what would be linked
108
+ wtlink link --type symbolic # Use symlinks instead of hard links
109
+ wtlink link --yes # Skip confirmation prompts
110
+
111
+ # validate - Check manifest integrity
112
+ wtlink validate # Validate against current worktree
113
+ wtlink validate ../other-wt # Validate against specific source
114
+ ```
115
+
116
+ **How it works:**
117
+
118
+ 1. **Discover** — Scans for git-ignored files in your repository
119
+ 2. **Decide** — Interactive UI to categorize each file (link, track, or skip)
120
+ 3. **Link** — Creates hard links from main worktree to feature worktrees
121
+ 4. **Validate** — Ensures manifest entries exist and remain git-ignored
122
+
123
+ **Interactive UI navigation:**
124
+
125
+ | Key | Action |
126
+ | --- | ------------------------------------------------ |
127
+ | ↑/↓ | Navigate file list |
128
+ | ←/→ | Navigate into/out of folders (hierarchical view) |
129
+ | A | Mark as "Will Link" (added to manifest) |
130
+ | C | Mark as "Track" (commented in manifest) |
131
+ | S | Mark as "Skip" (not in manifest) |
132
+ | 0 | Toggle showing undecided items |
133
+ | 1 | Toggle showing "Will Link" items |
134
+ | 2 | Toggle showing "Track" items |
135
+ | 3 | Toggle showing "Skip" items |
136
+ | V | Toggle hierarchical/flat view |
137
+ | ? | Show help |
138
+ | Q | Save and quit |
139
+ | X | Cancel without saving |
140
+
141
+ **Folder operations:** Actions on folders apply to all files inside. The UI shows a breakdown of child states for each folder.
142
+
143
+ **Conflict detection:** When linking, if a file already exists at the destination with different content, you'll be prompted to:
144
+
145
+ - **Replace** — Delete destination and create link
146
+ - **Ignore** — Keep destination file as-is
147
+ - **Remove** — Remove entry from manifest
148
+
149
+ **Manifest format (`.wtlinkrc`):**
150
+
151
+ The manifest lives in your repository root and tracks which files to share:
152
+
153
+ ```text
154
+ .vscode/settings.json
155
+ .editorconfig
156
+ .env.local
157
+ # .vscode/launch.json
158
+ ```
159
+
160
+ - Active entries (no `#`) are hard-linked between worktrees
161
+ - Commented entries (`#`) are tracked but not currently linked
162
+ - Files marked "Skip" are not added to the manifest at all
163
+
164
+ **Best practices:**
165
+
166
+ ✅ **Good candidates for linking:**
167
+
168
+ - `.vscode/settings.json`, `.editorconfig` — Editor config
169
+ - `.env.local`, `.env.development` — Local environment variables
170
+ - `certificates/`, `credentials/` — Local dev certificates
171
+
172
+ ❌ **Not suitable for linking:**
173
+
174
+ - `node_modules/` — Use [pnpm](https://pnpm.io) for shared dependencies instead
175
+ - `dist/`, `build/` — Build artifacts should be separate per worktree
176
+ - `.git/` — Never link git internals
177
+
178
+ ## Configuration
179
+
180
+ Create a `.worktreerc` file in your repository root:
181
+
182
+ ```json
183
+ {
184
+ "sharedRepos": ["cluster-gitops", "infrastructure"],
185
+ "baseBranch": "main",
186
+ "draftPr": true
187
+ }
188
+ ```
189
+
190
+ ### Options
191
+
192
+ | Option | Type | Default | Description |
193
+ | ----------------- | -------- | --------------------- | ------------------------------------------ |
194
+ | `sharedRepos` | string[] | `[]` | Sibling repos to also create worktrees for |
195
+ | `baseBranch` | string | `"main"` | Base branch for new PRs |
196
+ | `draftPr` | boolean | `false` | Create PRs as drafts by default |
197
+ | `worktreePattern` | string | `"{repo}.pr{number}"` | Worktree directory naming pattern |
198
+ | `worktreeParent` | string | `".."` | Parent directory for worktrees |
199
+ | `branchPrefix` | string | `"claude"` | Prefix for auto-generated branch names |
200
+
201
+ > **Note:** File syncing between worktrees is managed by `wtlink` using its own `.wtlinkrc` manifest. See the [wtlink section](#wtlink) for details.
202
+
203
+ ## Example Workflow
204
+
205
+ ```bash
206
+ # Start in your main repo
207
+ cd ~/projects/my-app
208
+
209
+ # Create a new feature PR
210
+ newpr "Add dark mode support"
211
+ # → Creates branch: claude/add-dark-mode-support-xyz123
212
+ # → Creates PR: #42
213
+ # → Creates worktree: ~/projects/my-app.pr42
214
+ # → Switches to worktree
215
+
216
+ # Work on the feature in the dedicated worktree
217
+ # ... make changes, commit, push ...
218
+
219
+ # Need to work on another feature? No problem!
220
+ cd ~/projects/my-app
221
+ newpr "Fix login bug"
222
+ # → Creates another worktree: ~/projects/my-app.pr43
223
+
224
+ # List your worktrees
225
+ lswt
226
+ # WORKTREE BRANCH PR STATUS
227
+ # ~/projects/my-app main - -
228
+ # ~/projects/my-app.pr42 claude/add-dark-mode-xyz123 #42 open
229
+ # ~/projects/my-app.pr43 claude/fix-login-bug-abc456 #43 open
230
+
231
+ # After PRs are merged, clean up
232
+ cleanpr
233
+ # → Removes worktrees for merged PRs
234
+ # → Deletes local branches
235
+ ```
236
+
237
+ ## Development
238
+
239
+ ```bash
240
+ # Clone the repo
241
+ git clone https://github.com/camaradesuk/git-worktree-tools.git
242
+ cd git-worktree-tools
243
+
244
+ # Install dependencies
245
+ npm install
246
+
247
+ # Build
248
+ npm run build
249
+
250
+ # Test
251
+ npm test
252
+
253
+ # Link for local development
254
+ npm link
255
+ ```
256
+
257
+ ## License
258
+
259
+ MIT
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * cleanpr - Clean up PR worktrees after merge/close
4
+ *
5
+ * Usage:
6
+ * cleanpr # Interactive cleanup of merged/closed PRs
7
+ * cleanpr <PR_NUMBER> # Clean specific PR worktree
8
+ * cleanpr --all # Clean all merged/closed PRs
9
+ * cleanpr <PR_NUMBER> -r # Also delete remote branch
10
+ * cleanpr <PR_NUMBER> -f # Force removal with uncommitted changes
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=cleanpr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanpr.d.ts","sourceRoot":"","sources":["../../src/cli/cleanpr.ts"],"names":[],"mappings":";AACA;;;;;;;;;GASG"}