Skip to content

Commit e1d95fe

Browse files
Merge pull request #22 from felipeS/feature/setup-worktree
Add setup-worktree support with security checks and improved type safety
2 parents 972a449 + 8f01d88 commit e1d95fe

5 files changed

Lines changed: 15454 additions & 1 deletion

File tree

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,26 @@ wt new feature/deps -i pnpm
3030
wt new feature/vscode -e code
3131
```
3232

33+
### Create a new worktree with setup scripts
34+
35+
```bash
36+
wt setup <branchName> [options]
37+
```
38+
39+
Creates a new worktree and automatically runs setup commands from `worktrees.json` or `.cursor/worktrees.json`. This is useful for automating dependency installation, copying configuration files, or running custom setup scripts.
40+
41+
Options:
42+
- `-p, --path <path>`: Specify a custom path for the worktree
43+
- `-c, --checkout`: Create new branch if it doesn't exist and checkout automatically
44+
- `-i, --install <packageManager>`: Package manager to use for installing dependencies (npm, pnpm, bun, etc.)
45+
- `-e, --editor <editor>`: Editor to use for opening the worktree (overrides default editor)
46+
47+
Example:
48+
```bash
49+
wt setup feature/new-feature
50+
wt setup feature/quick-start -i pnpm
51+
```
52+
3353
### Create a new worktree from Pull Request Number
3454

3555
```bash
@@ -77,6 +97,60 @@ wt config path
7797

7898
The default editor will be used when creating new worktrees unless overridden with the `-e` flag.
7999

100+
### Setup Worktree Configuration
101+
102+
You can define setup commands in one of two locations to automatically execute them when using `wt setup`:
103+
104+
1. **Cursor's format**: `.cursor/worktrees.json` in the repository root
105+
2. **Generic format**: `worktrees.json` in the repository root
106+
107+
The tool checks for `.cursor/worktrees.json` first, then falls back to `worktrees.json`.
108+
109+
**Note:** Setup scripts only run when using the `wt setup` command. The `wt new` command will not execute setup scripts.
110+
111+
#### Format Options:
112+
113+
**Option 1: `worktrees.json` (recommended for new projects):**
114+
```json
115+
{
116+
"setup-worktree": [
117+
"npm install",
118+
"cp $ROOT_WORKTREE_PATH/.local.env .local.env",
119+
"echo 'Setup complete'"
120+
]
121+
}
122+
```
123+
124+
**Option 2: `.cursor/worktrees.json` (Cursor's native format):**
125+
```json
126+
[
127+
"npm install",
128+
"cp $ROOT_WORKTREE_PATH/.local.env .local.env",
129+
"echo 'Setup complete'"
130+
]
131+
```
132+
133+
#### Security Features
134+
135+
- **Command Blocklist**: Dangerous command patterns are automatically blocked
136+
- **Blocked Patterns**:
137+
- `rm -rf` and recursive deletions
138+
- `sudo` and privilege escalation commands
139+
- `chmod`, `chown` permission changes
140+
- Piping downloads to shell (`curl | sh`, `wget | sh`)
141+
- Disk operations (`dd`, `mkfs`, `format`)
142+
- System commands (`shutdown`, `reboot`, `kill -9`)
143+
- Fork bombs and malicious patterns
144+
- **Flexible Execution**: Any command not matching dangerous patterns is allowed, giving you full flexibility for legitimate setup tasks
145+
146+
#### Execution Details
147+
148+
- Commands are executed in the new worktree directory
149+
- The `$ROOT_WORKTREE_PATH` environment variable is available, pointing to the main repository root
150+
- Commands run with shell execution, so complex commands and piping are supported
151+
- If a command fails, the error is logged, but setup continues with the next command
152+
- The setup runs after worktree creation but before dependency installation (if `--install` is used)
153+
80154
### List worktrees
81155

82156
```bash

0 commit comments

Comments
 (0)