@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.
- package/LICENSE +21 -0
- package/README.md +259 -0
- package/dist/cli/cleanpr.d.ts +13 -0
- package/dist/cli/cleanpr.d.ts.map +1 -0
- package/dist/cli/cleanpr.js +441 -0
- package/dist/cli/cleanpr.js.map +1 -0
- package/dist/cli/lswt.d.ts +11 -0
- package/dist/cli/lswt.d.ts.map +1 -0
- package/dist/cli/lswt.js +313 -0
- package/dist/cli/lswt.js.map +1 -0
- package/dist/cli/newpr.d.ts +11 -0
- package/dist/cli/newpr.d.ts.map +1 -0
- package/dist/cli/newpr.js +888 -0
- package/dist/cli/newpr.js.map +1 -0
- package/dist/cli/wtlink.d.ts +15 -0
- package/dist/cli/wtlink.d.ts.map +1 -0
- package/dist/cli/wtlink.js +124 -0
- package/dist/cli/wtlink.js.map +1 -0
- package/dist/e2e/cli.e2e.test.d.ts +2 -0
- package/dist/e2e/cli.e2e.test.d.ts.map +1 -0
- package/dist/e2e/cli.e2e.test.js +215 -0
- package/dist/e2e/cli.e2e.test.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/integration/git.integration.test.d.ts +2 -0
- package/dist/integration/git.integration.test.d.ts.map +1 -0
- package/dist/integration/git.integration.test.js +333 -0
- package/dist/integration/git.integration.test.js.map +1 -0
- package/dist/lib/colors.d.ts +59 -0
- package/dist/lib/colors.d.ts.map +1 -0
- package/dist/lib/colors.js +145 -0
- package/dist/lib/colors.js.map +1 -0
- package/dist/lib/colors.test.d.ts +2 -0
- package/dist/lib/colors.test.d.ts.map +1 -0
- package/dist/lib/colors.test.js +69 -0
- package/dist/lib/colors.test.js.map +1 -0
- package/dist/lib/config.d.ts +58 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +91 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/config.test.d.ts +2 -0
- package/dist/lib/config.test.d.ts.map +1 -0
- package/dist/lib/config.test.js +84 -0
- package/dist/lib/config.test.js.map +1 -0
- package/dist/lib/constants.d.ts +37 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +37 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/errors.d.ts +88 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +112 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/errors.test.d.ts +2 -0
- package/dist/lib/errors.test.d.ts.map +1 -0
- package/dist/lib/errors.test.js +117 -0
- package/dist/lib/errors.test.js.map +1 -0
- package/dist/lib/git.d.ts +224 -0
- package/dist/lib/git.d.ts.map +1 -0
- package/dist/lib/git.js +524 -0
- package/dist/lib/git.js.map +1 -0
- package/dist/lib/git.test.d.ts +2 -0
- package/dist/lib/git.test.d.ts.map +1 -0
- package/dist/lib/git.test.js +402 -0
- package/dist/lib/git.test.js.map +1 -0
- package/dist/lib/github.d.ts +82 -0
- package/dist/lib/github.d.ts.map +1 -0
- package/dist/lib/github.js +254 -0
- package/dist/lib/github.js.map +1 -0
- package/dist/lib/github.test.d.ts +2 -0
- package/dist/lib/github.test.d.ts.map +1 -0
- package/dist/lib/github.test.js +258 -0
- package/dist/lib/github.test.js.map +1 -0
- package/dist/lib/prompts.d.ts +39 -0
- package/dist/lib/prompts.d.ts.map +1 -0
- package/dist/lib/prompts.js +213 -0
- package/dist/lib/prompts.js.map +1 -0
- package/dist/lib/prompts.test.d.ts +2 -0
- package/dist/lib/prompts.test.d.ts.map +1 -0
- package/dist/lib/prompts.test.js +250 -0
- package/dist/lib/prompts.test.js.map +1 -0
- package/dist/lib/state-detection.d.ts +65 -0
- package/dist/lib/state-detection.d.ts.map +1 -0
- package/dist/lib/state-detection.js +186 -0
- package/dist/lib/state-detection.js.map +1 -0
- package/dist/lib/state-detection.test.d.ts +2 -0
- package/dist/lib/state-detection.test.d.ts.map +1 -0
- package/dist/lib/state-detection.test.js +164 -0
- package/dist/lib/state-detection.test.js.map +1 -0
- package/dist/lib/wtlink/index.d.ts +5 -0
- package/dist/lib/wtlink/index.d.ts.map +1 -0
- package/dist/lib/wtlink/index.js +7 -0
- package/dist/lib/wtlink/index.js.map +1 -0
- package/dist/lib/wtlink/link-configs.d.ts +10 -0
- package/dist/lib/wtlink/link-configs.d.ts.map +1 -0
- package/dist/lib/wtlink/link-configs.js +411 -0
- package/dist/lib/wtlink/link-configs.js.map +1 -0
- package/dist/lib/wtlink/link-configs.test.d.ts +2 -0
- package/dist/lib/wtlink/link-configs.test.d.ts.map +1 -0
- package/dist/lib/wtlink/link-configs.test.js +179 -0
- package/dist/lib/wtlink/link-configs.test.js.map +1 -0
- package/dist/lib/wtlink/main-menu.d.ts +2 -0
- package/dist/lib/wtlink/main-menu.d.ts.map +1 -0
- package/dist/lib/wtlink/main-menu.js +149 -0
- package/dist/lib/wtlink/main-menu.js.map +1 -0
- package/dist/lib/wtlink/manage-manifest.d.ts +9 -0
- package/dist/lib/wtlink/manage-manifest.d.ts.map +1 -0
- package/dist/lib/wtlink/manage-manifest.js +1262 -0
- package/dist/lib/wtlink/manage-manifest.js.map +1 -0
- package/dist/lib/wtlink/validate-manifest.d.ts +6 -0
- package/dist/lib/wtlink/validate-manifest.d.ts.map +1 -0
- package/dist/lib/wtlink/validate-manifest.js +51 -0
- package/dist/lib/wtlink/validate-manifest.js.map +1 -0
- package/dist/lib/wtlink/validate-manifest.test.d.ts +2 -0
- package/dist/lib/wtlink/validate-manifest.test.d.ts.map +1 -0
- package/dist/lib/wtlink/validate-manifest.test.js +115 -0
- package/dist/lib/wtlink/validate-manifest.test.js.map +1 -0
- 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"}
|