Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat(step): add copy-ignored command for syncing .worktreeinclude files (#469)

Maximilian Roosbd2a7c16e9c2
diff --git a/.claude-plugin/skills/worktrunk/reference/hook.md b/.claude-plugin/skills/worktrunk/reference/hook.md
index f44ead521..77359251c 100644
--- a/.claude-plugin/skills/worktrunk/reference/hook.md
+++ b/.claude-plugin/skills/worktrunk/reference/hook.md
@@ -202,45 +202,37 @@ Many tasks work well in `post-start` — they'll likely be ready by the time you
### Copying untracked files
-Git worktrees share the repository but not untracked files. Common files to copy or link:
+Git worktrees share the repository but not untracked files. Common files to copy:
- **Dependencies**: `node_modules/`, `.venv/`, `target/`, `vendor/`, `Pods/`
- **Build caches**: `.cache/`, `.next/`, `.parcel-cache/`, `.turbo/`
- **Generated assets**: Images, ML models, binaries too large for git
- **Environment files**: `.env` (if not generated per-worktree)
-Three strategies:
+Use `wt step copy-ignored` to copy files listed in `.worktreeinclude` that are also gitignored:
-| Strategy | Speed | Disk | State |
-|----------|-------|------|-------|
-| **Symlink** | Instant | Shared | Shared (changes affect all worktrees) |
-| **Copy** | Slow | Full duplicate | Isolated |
-| **Copy-on-write** | Instant | Shared until modified | Isolated |
+```toml
+[post-create]
+copy = "wt step copy-ignored"
+```
-### Copy-on-write for disk efficiency
+Create a `.worktreeinclude` file in your repository root listing patterns to copy (uses gitignore syntax):
-Copy-on-write (CoW) creates instant clones that share disk space until modified. Perfect for large directories.
+```gitignore
+# .worktreeinclude
+.env
+node_modules/
+target/
+.cache/
+```
-| OS | Filesystem | Command |
-|----|------------|---------|
-| macOS | APFS | `cp -c` |
-| Linux | Btrfs, XFS | `cp --reflink=auto` |
-| Windows | ReFS | No shell equivalent (requires API) |
+Files are only copied if they match **both** `.worktreeinclude` **and** are gitignored — this prevents accidentally copying tracked files.
-Cross-platform pattern that auto-detects and falls back gracefully:
-
-```toml
-[post-create]
-deps = """
-if cp -c /dev/null /dev/null 2>/dev/null; then
- cp -c -r {{ main_worktree_path }}/node_modules .
-elif cp --reflink=auto /dev/null /dev/null 2>/dev/null; then
- cp --reflink=auto -r {{ main_worktree_path }}/node_modules .
-else
- cp -r {{ main_worktree_path }}/node_modules .
-fi
-"""
-```
+**Features:**
+- Uses copy-on-write (reflink) when available for instant, space-efficient copies
+- Handles nested `.gitignore` files, global excludes, and `.git/info/exclude`
+- Skips existing files (safe to re-run)
+- Skips symlinks and `.git` entries
### Dev servers
@@ -393,19 +385,14 @@ Each ecosystem has quirks that affect hook design. Contributions welcome for lan
### Rust
-The `target/` directory is huge (often 1-10GB) and benefits most from CoW. Worktrunk's own config seeds compiled dependencies:
+The `target/` directory is huge (often 1-10GB). Use `wt step copy-ignored` with a `.worktreeinclude`:
-```toml
-[post-start]
-deps = """
-[ -d {{ main_worktree_path }}/target/debug/deps ] && [ ! -e target ] &&
-mkdir -p target/debug/deps &&
-cp -c {{ main_worktree_path }}/target/debug/deps/*.rlib {{ main_worktree_path }}/target/debug/deps/*.rmeta target/debug/deps/ &&
-cp -cR {{ main_worktree_path }}/target/debug/.fingerprint {{ main_worktree_path }}/target/debug/build target/debug/
-"""
+```gitignore
+# .worktreeinclude
+target/
```
-This cuts first build from ~68s to ~3s by reusing compiled dependencies. The check `[ ! -e target ]` skips if target already exists.
+This copies `target/` using copy-on-write (reflink), cutting first build from ~68s to ~3s by reusing compiled dependencies.
### Python
@@ -425,11 +412,12 @@ venv = "python -m venv .venv && .venv/bin/pip install -r requirements.txt"
### Node.js
-`node_modules/` is large but mostly static. CoW works well:
+`node_modules/` is large but mostly static. Add to `.worktreeinclude`:
-```toml
-[post-create]
-deps = "cp -c -r {{ main_worktree_path }}/node_modules . 2>/dev/null || npm ci"
+```gitignore
+# .worktreeinclude
+node_modules/
+.env
```
If the project has no native dependencies, symlinks are even faster:
diff --git a/.claude-plugin/skills/worktrunk/reference/step.md b/.claude-plugin/skills/worktrunk/reference/step.md
index 036493559..bbb6d8da2 100644
--- a/.claude-plugin/skills/worktrunk/reference/step.md
+++ b/.claude-plugin/skills/worktrunk/reference/step.md
@@ -26,6 +26,7 @@ wt step push
- `squash` — Squash all branch commits into one with [LLM-generated message](https://worktrunk.dev/llm-commits/)
- `rebase` — Rebase onto target branch
- `push` — Fast-forward target to current branch
+- `copy-ignored` — Copy files listed in `.worktreeinclude`
- `for-each` — [experimental] Run a command in every worktree
## Options
@@ -71,11 +72,12 @@ wt step - Run individual operations
Usage: <b><span class=c>wt step</span></b> <span class=c>[OPTIONS]</span> <span class=c>&lt;COMMAND&gt;</span>
<b><span class=g>Commands:</span></b>
- <b><span class=c>commit</span></b> Commit changes with LLM commit message
- <b><span class=c>squash</span></b> Squash commits since branching
- <b><span class=c>push</span></b> Fast-forward target to current branch
- <b><span class=c>rebase</span></b> Rebase onto target
- <b><span class=c>for-each</span></b> [experimental] Run command in each worktree
+ <b><span class=c>commit</span></b> Commit changes with LLM commit message
+ <b><span class=c>squash</span></b> Squash commits since branching
+ <b><span class=c>push</span></b> Fast-forward target to current branch
+ <b><span class=c>rebase</span></b> Rebase onto target
+ <b><span class=c>copy-ignored</span></b> Copy <b>.worktreeinclude</b> files to another worktree
+ <b><span class=c>for-each</span></b> [experimental] Run command in each worktree
<b><span class=g>Options:</span></b>
<b><span class=c>-h</span></b>, <b><span class=c>--help</span></b>
diff --git a/.claude-plugin/skills/worktrunk/reference/tips-patterns.md b/.claude-plugin/skills/worktrunk/reference/tips-patterns.md
index 0df7c7e57..3b0af2416 100644
--- a/.claude-plugin/skills/worktrunk/reference/tips-patterns.md
+++ b/.claude-plugin/skills/worktrunk/reference/tips-patterns.md
@@ -14,15 +14,24 @@ wsc feature -- 'Fix GH #322' # Runs `claude 'Fix GH #322'`
## Eliminate cold starts
-`post-create` hooks install deps and copy caches. On macOS, use copy-on-write for instant cache cloning:
+Use `wt step copy-ignored` in a `post-create` or `post-start` hook to copy gitignored files (caches, dependencies) between worktrees:
```toml
[post-create]
-"cache" = "cp -c -r ../.cache .cache" # APFS clones (instant, no disk space)
-"install" = "npm ci"
+copy = "wt step copy-ignored"
+install = "npm ci"
```
-See [Designing effective hooks](https://worktrunk.dev/hook/#designing-effective-hooks) for cross-platform CoW commands, language-specific tips, and more patterns.
+Create a `.worktreeinclude` file listing what to copy (uses gitignore syntax):
+
+```gitignore
+# .worktreeinclude
+.cache/
+node_modules/
+target/
+```
+
+See [Copying untracked files](https://worktrunk.dev/hook/#copying-untracked-files) for more details.
## Dev server per worktree
diff --git a/.config/wt.toml b/.config/wt.toml
index 36f5637c9..58a1d2f85 100644
--- a/.config/wt.toml
+++ b/.config/wt.toml
@@ -1,11 +1,6 @@
[post-start]
-# Seed compiled deps from main worktree using CoW (~3s vs ~68s full rebuild)
-deps = """
-[ -d {{ repo_path }}/target/debug/deps ] && [ ! -e target ] &&
-mkdir -p target/debug/deps &&
-cp -c {{ repo_path }}/target/debug/deps/*.rlib {{ repo_path }}/target/debug/deps/*.rmeta target/debug/deps/ &&
-cp -cR {{ repo_path }}/target/debug/.fingerprint {{ repo_path }}/target/debug/build target/debug/
-"""
+# Copy target/ from main worktree using CoW (~3s vs ~68s full rebuild)
+deps = "wt step copy-ignored"
assets = "./dev/fetch-assets"
docs = "cd docs && zola serve -p {{ branch | hash_port }}"
diff --git a/.worktreeinclude b/.worktreeinclude
new file mode 100644
index 000000000..38dc980ce
--- /dev/null
+++ b/.worktreeinclude
@@ -0,0 +1,4 @@
+# Files to copy between worktrees (must also be gitignored)
+# Used by: wt step copy-ignored
+
+target/
diff --git a/Cargo.lock b/Cargo.lock
index c4784652f..b72ebde4a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1082,6 +1082,19 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
+[[package]]
+name = "globset"
+version = "0.4.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "52dfc19153a48bde0cbd630453615c8151bce3a5adfac7a0aebfbf0a1e1f57e3"
+dependencies = [
+ "aho-corasick",
+ "bstr",
+ "log",
+ "regex-automata",
+ "regex-syntax",
+]
+
[[package]]
name = "half"
version = "2.7.1"
@@ -1174,6 +1187,22 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd62e6b5e86ea8eeeb8db1de02880a6abc01a397b2ebb64b5d74ac255318f5cb"
+[[package]]
+name = "ignore"
+version = "0.4.25"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d3d782a365a015e0f5c04902246139249abf769125006fbe7649e2ee88169b4a"
+dependencies = [
+ "crossbeam-deque",
+ "globset",
+ "log",
+ "memchr",
+ "regex-automata",
+ "same-file",
+ "walkdir",
+ "winapi-util",
+]
+
[[package]]
name = "indexmap"
version = "2.12.1"
@@ -1840,6 +1869,18 @@ dependencies = [
"thiserror 2.0.17",
]
+[[package]]
+name = "reflink-copy"
+version = "0.1.28"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "23bbed272e39c47a095a5242218a67412a220006842558b03fe2935e8f3d7b92"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "rustix",
+ "windows",
+]
+
[[package]]
name = "regex"
version = "1.12.2"
@@ -2860,6 +2901,27 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
+[[package]]
+name = "windows"
+version = "0.62.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580"
+dependencies = [
+ "windows-collections",
+ "windows-core",
+ "windows-future",
+ "windows-numerics",
+]
+
+[[package]]
+name = "windows-collections"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "23b2d95af1a8a14a3c7367e1ed4fc9c20e0a26e79551b1454d72583c97cc6610"
+dependencies = [
+ "windows-core",
+]
+
[[package]]
name = "windows-core"
version = "0.62.2"
@@ -2873,6 +2935,17 @@ dependencies = [
"windows-strings",
]
+[[package]]
+name = "windows-future"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb"
+dependencies = [
+ "windows-core",
+ "windows-link",
+ "windows-threading",
+]
+
[[package]]
name = "windows-implement"
version = "0.60.2"
@@ -2901,6 +2974,16 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
+[[package]]
+name = "windows-numerics"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26"
+dependencies = [
+ "windows-core",
+ "windows-link",
+]
+
[[package]]
name = "windows-result"
version = "0.4.1"
@@ -2979,6 +3062,15 @@ dependencies = [
"windows_x86_64_msvc 0.53.1",
]
+[[package]]
+name = "windows-threading"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37"
+dependencies = [
+ "windows-link",
+]
+
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
@@ -3128,6 +3220,7 @@ dependencies = [
"env_logger",
"etcetera",
"home",
+ "ignore",
"indexmap",
"insta",
"insta-cmd",
@@ -3141,6 +3234,7 @@ dependencies = [
"portable-pty",
"rayon",
"rayon-join-macro",
+ "reflink-copy",
"regex",
"rstest",
"serde",
diff --git a/Cargo.toml b/Cargo.toml
index 8bfec5020..cb68a2bfe 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -113,6 +113,8 @@ termimad = "0.34.1"
rayon-join-macro = "0.1.1"
urlencoding = "2.1"
regex = "1.12"
+ignore = "0.4"
+reflink-copy = "0.1"
[target.'cfg(unix)'.dependencies]
skim = "0.20"
diff --git a/docs/content/hook.md b/docs/content/hook.md
index 7f5a488dd..abda845a9 100644
--- a/docs/content/hook.md
+++ b/docs/content/hook.md
@@ -210,45 +210,37 @@ Many tasks work well in `post-start` — they'll likely be ready by the time you
### Copying untracked files
-Git worktrees share the repository but not untracked files. Common files to copy or link:
+Git worktrees share the repository but not untracked files. Common files to copy:
- **Dependencies**: `node_modules/`, `.venv/`, `target/`, `vendor/`, `Pods/`
- **Build caches**: `.cache/`, `.next/`, `.parcel-cache/`, `.turbo/`
- **Generated assets**: Images, ML models, binaries too large for git
- **Environment files**: `.env` (if not generated per-worktree)
-Three strategies:
+Use `wt step copy-ignored` to copy files listed in `.worktreeinclude` that are also gitignored:
-| Strategy | Speed | Disk | State |
-|----------|-------|------|-------|
-| **Symlink** | Instant | Shared | Shared (changes affect all worktrees) |
-| **Copy** | Slow | Full duplicate | Isolated |
-| **Copy-on-write** | Instant | Shared until modified | Isolated |
+```toml
+[post-create]
+copy = "wt step copy-ignored"
+```
-### Copy-on-write for disk efficiency
+Create a `.worktreeinclude` file in your repository root listing patterns to copy (uses gitignore syntax):
-Copy-on-write (CoW) creates instant clones that share disk space until modified. Perfect for large directories.
+```gitignore
+# .worktreeinclude
+.env
+node_modules/
+target/
+.cache/
+```
-| OS | Filesystem | Command |
-|----|------------|---------|
-| macOS | APFS | `cp -c` |
-| Linux | Btrfs, XFS | `cp --reflink=auto` |
-| Windows | ReFS | No shell equivalent (requires API) |
+Files are only copied if they match **both** `.worktreeinclude` **and** are gitignored — this prevents accidentally copying tracked files.
-Cross-platform pattern that auto-detects and falls back gracefully:
-
-```toml
-[post-create]
-deps = """
-if cp -c /dev/null /dev/null 2>/dev/null; then
- cp -c -r {{ main_worktree_path }}/node_modules .
-elif cp --reflink=auto /dev/null /dev/null 2>/dev/null; then
- cp --reflink=auto -r {{ main_worktree_path }}/node_modules .
-else
- cp -r {{ main_worktree_path }}/node_modules .
-fi
-"""
-```
+**Features:**
+- Uses copy-on-write (reflink) when available for instant, space-efficient copies
+- Handles nested `.gitignore` files, global excludes, and `.git/info/exclude`
+- Skips existing files (safe to re-run)
+- Skips symlinks and `.git` entries
### Dev servers
@@ -401,19 +393,14 @@ Each ecosystem has quirks that affect hook design. Contributions welcome for lan
### Rust
-The `target/` directory is huge (often 1-10GB) and benefits most from CoW. Worktrunk's own config seeds compiled dependencies:
+The `target/` directory is huge (often 1-10GB). Use `wt step copy-ignored` with a `.worktreeinclude`:
-```toml
-[post-start]
-deps = """
-[ -d {{ main_worktree_path }}/target/debug/deps ] && [ ! -e target ] &&
-mkdir -p target/debug/deps &&
-cp -c {{ main_worktree_path }}/target/debug/deps/*.rlib {{ main_worktree_path }}/target/debug/deps/*.rmeta target/debug/deps/ &&
-cp -cR {{ main_worktree_path }}/target/debug/.fingerprint {{ main_worktree_path }}/target/debug/build target/debug/
-"""
+```gitignore
+# .worktreeinclude
+target/
```
-This cuts first build from ~68s to ~3s by reusing compiled dependencies. The check `[ ! -e target ]` skips if target already exists.
+This copies `target/` using copy-on-write (reflink), cutting first build from ~68s to ~3s by reusing compiled dependencies.
### Python
@@ -433,11 +420,12 @@ venv = "python -m venv .venv && .venv/bin/pip install -r requirements.txt"
### Node.js
-`node_modules/` is large but mostly static. CoW works well:
+`node_modules/` is large but mostly static. Add to `.worktreeinclude`:
-```toml
-[post-create]
-deps = "cp -c -r {{ main_worktree_path }}/node_modules . 2>/dev/null || npm ci"
+```gitignore
+# .worktreeinclude
+node_modules/
+.env
```
If the project has no native dependencies, symlinks are even faster:
diff --git a/docs/content/step.md b/docs/content/step.md
index 6c0dd804c..c1021bbad 100644
--- a/docs/content/step.md
+++ b/docs/content/step.md
@@ -34,6 +34,7 @@ wt step push
- `squash` — Squash all branch commits into one with [LLM-generated message](@/llm-commits.md)
- `rebase` — Rebase onto target branch
- `push` — Fast-forward target to current branch
+- `copy-ignored` — Copy files listed in `.worktreeinclude`
- `for-each` — [experimental] Run a command in every worktree
## Options
@@ -85,11 +86,12 @@ wt step - Run individual operations
Usage: <b><span class=c>wt step</span></b> <span class=c>[OPTIONS]</span> <span class=c>&lt;COMMAND&gt;</span>
<b><span class=g>Commands:</span></b>
- <b><span class=c>commit</span></b> Commit changes with LLM commit message
- <b><span class=c>squash</span></b> Squash commits since branching
- <b><span class=c>push</span></b> Fast-forward target to current branch
- <b><span class=c>rebase</span></b> Rebase onto target
- <b><span class=c>for-each</span></b> [experimental] Run command in each worktree
+ <b><span class=c>commit</span></b> Commit changes with LLM commit message
+ <b><span class=c>squash</span></b> Squash commits since branching
+ <b><span class=c>push</span></b> Fast-forward target to current branch
+ <b><span class=c>rebase</span></b> Rebase onto target
+ <b><span class=c>copy-ignored</span></b> Copy <b>.worktreeinclude</b> files to another worktree
+ <b><span class=c>for-each</span></b> [experimental] Run command in each worktree
<b><span class=g>Options:</span></b>
<b><span class=c>-h</span></b>, <b><span class=c>--help</span></b>
diff --git a/docs/content/tips-patterns.md b/docs/content/tips-patterns.md
index daf6a4d46..d6d061d5a 100644
--- a/docs/content/tips-patterns.md
+++ b/docs/content/tips-patterns.md
@@ -20,15 +20,24 @@ wsc feature -- 'Fix GH #322' # Runs `claude 'Fix GH #322'`
## Eliminate cold starts
-`post-create` hooks install deps and copy caches. On macOS, use copy-on-write for instant cache cloning:
+Use `wt step copy-ignored` in a `post-create` or `post-start` hook to copy gitignored files (caches, dependencies) between worktrees:
```toml
[post-create]
-"cache" = "cp -c -r ../.cache .cache" # APFS clones (instant, no disk space)
-"install" = "npm ci"
+copy = "wt step copy-ignored"
+install = "npm ci"
```
-See [Designing effective hooks](@/hook.md#designing-effective-hooks) for cross-platform CoW commands, language-specific tips, and more patterns.
+Create a `.worktreeinclude` file listing what to copy (uses gitignore syntax):
+
+```gitignore
+# .worktreeinclude
+.cache/
+node_modules/
+target/
+```
+
+See [Copying untracked files](@/hook.md#copying-untracked-files) for more details.
## Dev server per worktree
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index a65cca3aa..a17b3e743 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -294,6 +294,30 @@ pub enum StepCommand {
target: Option<String>,
},
+ /// Copy `.worktreeinclude` files to another worktree
+ ///
+ /// Copies files listed in `.worktreeinclude` that are also gitignored.
+ /// Useful in post-create hooks to sync local config files
+ /// (`.env`, IDE settings) to new worktrees. Skips symlinks and existing
+ /// files.
+ CopyIgnored {
+ /// Source worktree branch
+ ///
+ /// Defaults to main worktree.
+ #[arg(long, add = crate::completion::worktree_only_completer())]
+ from: Option<String>,
+
+ /// Destination worktree branch
+ ///
+ /// Defaults to current worktree.
+ #[arg(long, add = crate::completion::worktree_only_completer())]
+ to: Option<String>,
+
+ /// Show what would be copied
+ #[arg(long)]
+ dry_run: bool,
+ },
+
/// \[experimental\] Run command in each worktree
#[command(
after_long_help = r#"Executes a command sequentially in every worktree with real-time output. Continues on failure and shows a summary at the end.
@@ -1072,6 +1096,7 @@ wt step push
- `squash` — Squash all branch commits into one with [LLM-generated message](@/llm-commits.md)
- `rebase` — Rebase onto target branch
- `push` — Fast-forward target to current branch
+- `copy-ignored` — Copy files listed in `.worktreeinclude`
- `for-each` — [experimental] Run a command in every worktree
## Options
@@ -1328,45 +1353,37 @@ Many tasks work well in `post-start` — they'll likely be ready by the time you
### Copying untracked files
-Git worktrees share the repository but not untracked files. Common files to copy or link:
+Git worktrees share the repository but not untracked files. Common files to copy:
- **Dependencies**: `node_modules/`, `.venv/`, `target/`, `vendor/`, `Pods/`
- **Build caches**: `.cache/`, `.next/`, `.parcel-cache/`, `.turbo/`
- **Generated assets**: Images, ML models, binaries too large for git
- **Environment files**: `.env` (if not generated per-worktree)
-Three strategies:
-
-| Strategy | Speed | Disk | State |
-|----------|-------|------|-------|
-| **Symlink** | Instant | Shared | Shared (changes affect all worktrees) |
-| **Copy** | Slow | Full duplicate | Isolated |
-| **Copy-on-write** | Instant | Shared until modified | Isolated |
+Use `wt step copy-ignored` to copy files listed in `.worktreeinclude` that are also gitignored:
-### Copy-on-write for disk efficiency
+```toml
+[post-create]
+copy = "wt step copy-ignored"
+```
-Copy-on-write (CoW) creates instant clones that share disk space until modified. Perfect for large directories.
+Create a `.worktreeinclude` file in your repository root listing patterns to copy (uses gitignore syntax):
-| OS | Filesystem | Command |
-|----|------------|---------|
-| macOS | APFS | `cp -c` |
-| Linux | Btrfs, XFS | `cp --reflink=auto` |
-| Windows | ReFS | No shell equivalent (requires API) |
+```gitignore
+# .worktreeinclude
+.env
+node_modules/
+target/
+.cache/
+```
-Cross-platform pattern that auto-detects and falls back gracefully:
+Files are only copied if they match **both** `.worktreeinclude` **and** are gitignored — this prevents accidentally copying tracked files.
-```toml
-[post-create]
-deps = """
-if cp -c /dev/null /dev/null 2>/dev/null; then
- cp -c -r {{ main_worktree_path }}/node_modules .
-elif cp --reflink=auto /dev/null /dev/null 2>/dev/null; then
- cp --reflink=auto -r {{ main_worktree_path }}/node_modules .
-else
- cp -r {{ main_worktree_path }}/node_modules .
-fi
-"""
-```
+**Features:**
+- Uses copy-on-write (reflink) when available for instant, space-efficient copies
+- Handles nested `.gitignore` files, global excludes, and `.git/info/exclude`
+- Skips existing files (safe to re-run)
+- Skips symlinks and `.git` entries
### Dev servers
@@ -1519,19 +1536,14 @@ Each ecosystem has quirks that affect hook design. Contributions welcome for lan
### Rust
-The `target/` directory is huge (often 1-10GB) and benefits most from CoW. Worktrunk's own config seeds compiled dependencies:
+The `target/` directory is huge (often 1-10GB). Use `wt step copy-ignored` with a `.worktreeinclude`:
-```toml
-[post-start]
-deps = """
-[ -d {{ main_worktree_path }}/target/debug/deps ] && [ ! -e target ] &&
-mkdir -p target/debug/deps &&
-cp -c {{ main_worktree_path }}/target/debug/deps/*.rlib {{ main_worktree_path }}/target/debug/deps/*.rmeta target/debug/deps/ &&
-cp -cR {{ main_worktree_path }}/target/debug/.fingerprint {{ main_worktree_path }}/target/debug/build target/debug/
-"""
+```gitignore
+# .worktreeinclude
+target/
```
-This cuts first build from ~68s to ~3s by reusing compiled dependencies. The check `[ ! -e target ]` skips if target already exists.
+This copies `target/` using copy-on-write (reflink), cutting first build from ~68s to ~3s by reusing compiled dependencies.
### Python
@@ -1551,11 +1563,12 @@ venv = "python -m venv .venv && .venv/bin/pip install -r requirements.txt"
### Node.js
-`node_modules/` is large but mostly static. CoW works well:
+`node_modules/` is large but mostly static. Add to `.worktreeinclude`:
-```toml
-[post-create]
-deps = "cp -c -r {{ main_worktree_path }}/node_modules . 2>/dev/null || npm ci"
+```gitignore
+# .worktreeinclude
+node_modules/
+.env
```
If the project has no native dependencies, symlinks are even faster:
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index cfdbaac29..bdb3489ee 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -36,7 +36,8 @@ pub use merge::{MergeOptions, execute_pre_remove_commands, handle_merge};
#[cfg(unix)]
pub use select::handle_select;
pub use step_commands::{
- RebaseResult, SquashResult, handle_rebase, handle_squash, step_commit, step_show_squash_prompt,
+ RebaseResult, SquashResult, handle_rebase, handle_squash, step_commit, step_copy_ignored,
+ step_show_squash_prompt,
};
pub use worktree::{
ResolutionContext, compute_worktree_path, handle_remove, handle_remove_current, handle_switch,
diff --git a/src/commands/step_commands.rs b/src/commands/step_commands.rs
index 723e7033b..86be0a022 100644
--- a/src/commands/step_commands.rs
+++ b/src/commands/step_commands.rs
@@ -5,6 +5,9 @@
//! - `handle_squash` - Squash commits into one
//! - `step_show_squash_prompt` - Show squash prompt without executing
//! - `handle_rebase` - Rebase onto target branch
+//! - `step_copy_ignored` - Copy gitignored files matching .worktreeinclude
+
+use std::path::Path;
use anyhow::Context;
use color_print::cformat;
@@ -404,6 +407,218 @@ pub fn handle_rebase(target: Option<&str>) -> anyhow::Result<RebaseResult> {
Ok(RebaseResult::Rebased)
}
+/// Handle `wt step copy-ignored` command
+///
+/// Copies files matching the intersection of `.worktreeinclude` and gitignored files
+/// from a source worktree to a destination worktree. Uses COW (reflink) when
+/// available for efficient copying of large directories like `target/`.
+pub fn step_copy_ignored(
+ from: Option<&str>,
+ to: Option<&str>,
+ dry_run: bool,
+) -> anyhow::Result<()> {
+ use ignore::gitignore::GitignoreBuilder;
+ use std::fs;
+
+ let repo = Repository::current();
+
+ // Resolve source and destination worktree paths
+ let (source_path, source_context) = match from {
+ Some(branch) => {
+ let path = repo
+ .worktree_for_branch(branch)?
+ .ok_or_else(|| anyhow::anyhow!("No worktree found for branch '{}'", branch))?;
+ (path, branch.to_string())
+ }
+ None => (repo.worktree_base()?, repo.default_branch()?.to_string()),
+ };
+
+ let dest_path = match to {
+ Some(branch) => repo
+ .worktree_for_branch(branch)?
+ .ok_or_else(|| anyhow::anyhow!("No worktree found for branch '{}'", branch))?,
+ None => repo.worktree_root()?.to_path_buf(),
+ };
+
+ if source_path == dest_path {
+ crate::output::print(info_message("Source and destination are the same worktree"))?;
+ return Ok(());
+ }
+
+ // Check for .worktreeinclude file
+ let include_path = source_path.join(".worktreeinclude");
+ if !include_path.exists() {
+ crate::output::print(info_message(cformat!(
+ "No <bold>.worktreeinclude</> file found"
+ )))?;
+ return Ok(());
+ }
+
+ // Get ignored entries from git
+ // --directory stops at directory boundaries (avoids listing thousands of files in target/)
+ let ignored_entries = list_ignored_entries(&source_path, &source_context)?;
+
+ // Build include matcher from .worktreeinclude
+ let include_matcher = {
+ let mut builder = GitignoreBuilder::new(&source_path);
+ if let Some(err) = builder.add(&include_path) {
+ return Err(anyhow::anyhow!("Error parsing .worktreeinclude: {}", err));
+ }
+ builder.build().context("Failed to build include matcher")?
+ };
+
+ // Filter to entries that match .worktreeinclude
+ let entries_to_copy: Vec<_> = ignored_entries
+ .into_iter()
+ .filter(|(path, is_dir)| include_matcher.matched(path, *is_dir).is_ignore())
+ .collect();
+
+ if entries_to_copy.is_empty() {
+ crate::output::print(info_message("No matching files to copy"))?;
+ return Ok(());
+ }
+
+ let mut copied_count = 0;
+
+ // Handle dry-run: show what would be copied in a gutter list
+ if dry_run {
+ let items: Vec<String> = entries_to_copy
+ .iter()
+ .map(|(src_entry, is_dir)| {
+ let relative = src_entry
+ .strip_prefix(&source_path)
+ .unwrap_or(src_entry.as_path());
+ let entry_type = if *is_dir { "dir" } else { "file" };
+ format!("{} ({})", relative.display(), entry_type)
+ })
+ .collect();
+ let entry_word = if items.len() == 1 { "entry" } else { "entries" };
+ crate::output::print(info_message(format!(
+ "Would copy {} {}:\n{}",
+ items.len(),
+ entry_word,
+ format_with_gutter(&items.join("\n"), None)
+ )))?;
+ return Ok(());
+ }
+
+ // Copy entries
+ for (src_entry, is_dir) in &entries_to_copy {
+ // Paths from git ls-files are always under source_path
+ let relative = src_entry
+ .strip_prefix(&source_path)
+ .expect("git ls-files path under worktree");
+ let dest_entry = dest_path.join(relative);
+
+ if *is_dir {
+ copy_dir_recursive(src_entry, &dest_entry)?;
+ copied_count += 1;
+ } else {
+ if let Some(parent) = dest_entry.parent() {
+ fs::create_dir_all(parent)?;
+ }
+ // Skip existing files for idempotent hook usage
+ match reflink_copy::reflink_or_copy(src_entry, &dest_entry) {
+ Ok(_) => copied_count += 1,
+ Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => {}
+ Err(e) => return Err(e.into()),
+ }
+ }
+ }
+
+ // Show summary
+ let entry_word = if copied_count == 1 {
+ "entry"
+ } else {
+ "entries"
+ };
+ crate::output::print(success_message(format!(
+ "Copied {copied_count} {entry_word}"
+ )))?;
+
+ Ok(())
+}
+
+/// List ignored entries using git ls-files
+///
+/// Uses `git ls-files --ignored --exclude-standard -o --directory` which:
+/// - Handles all gitignore sources (global, .gitignore, .git/info/exclude, nested)
+/// - Stops at directory boundaries (--directory) to avoid listing thousands of files
+fn list_ignored_entries(
+ worktree_path: &Path,
+ context: &str,
+) -> anyhow::Result<Vec<(std::path::PathBuf, bool)>> {
+ use std::process::Command;
+ use worktrunk::shell_exec;
+
+ let mut cmd = Command::new("git");
+ cmd.args([
+ "ls-files",
+ "--ignored",
+ "--exclude-standard",
+ "-o",
+ "--directory",
+ ])
+ .current_dir(worktree_path);
+
+ let output = shell_exec::run(&mut cmd, Some(context)).context("Failed to run git ls-files")?;
+
+ if !output.status.success() {
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ anyhow::bail!("git ls-files failed: {}", stderr.trim());
+ }
+
+ // Parse output: directories end with /
+ let entries = String::from_utf8_lossy(&output.stdout)
+ .lines()
+ .map(|line| {
+ let is_dir = line.ends_with('/');
+ let path = worktree_path.join(line.trim_end_matches('/'));
+ (path, is_dir)
+ })
+ .collect();
+
+ Ok(entries)
+}
+
+/// Copy a directory recursively using reflink (COW) for each file
+fn copy_dir_recursive(src: &Path, dest: &Path) -> anyhow::Result<()> {
+ use std::fs;
+ use std::io::ErrorKind;
+
+ fs::create_dir_all(dest)?;
+
+ for entry in fs::read_dir(src)? {
+ let entry = entry?;
+ let file_type = entry.file_type()?;
+
+ // Skip .git (file or directory) and symlinks
+ let file_name = entry.file_name();
+ if file_name == ".git" {
+ continue;
+ }
+ if file_type.is_symlink() {
+ continue;
+ }
+
+ let src_path = entry.path();
+ let dest_path = dest.join(file_name);
+
+ if file_type.is_dir() {
+ copy_dir_recursive(&src_path, &dest_path)?;
+ } else {
+ // Skip existing files for idempotent hook usage
+ match reflink_copy::reflink_or_copy(&src_path, &dest_path) {
+ Ok(_) => {}
+ Err(e) if e.kind() == ErrorKind::AlreadyExists => {}
+ Err(e) => return Err(e.into()),
+ }
+ }
+ }
+
+ Ok(())
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/src/completion.rs b/src/completion.rs
index 7c268266b..65187872c 100644
--- a/src/completion.rs
+++ b/src/completion.rs
@@ -142,6 +142,7 @@ pub fn branch_value_completer() -> ArgValueCompleter {
ArgValueCompleter::new(BranchCompleter {
suppress_with_create: false,
exclude_remote_only: false,
+ worktree_only: false,
})
}
@@ -151,6 +152,7 @@ pub fn worktree_branch_completer() -> ArgValueCompleter {
ArgValueCompleter::new(BranchCompleter {
suppress_with_create: true,
exclude_remote_only: false,
+ worktree_only: false,
})
}
@@ -159,6 +161,16 @@ pub fn local_branches_completer() -> ArgValueCompleter {
ArgValueCompleter::new(BranchCompleter {
suppress_with_create: false,
exclude_remote_only: true,
+ worktree_only: false,
+ })
+}
+
+/// Branch completion for commands that only operate on worktrees (e.g., copy-ignored).
+pub fn worktree_only_completer() -> ArgValueCompleter {
+ ArgValueCompleter::new(BranchCompleter {
+ suppress_with_create: false,
+ exclude_remote_only: false,
+ worktree_only: true,
})
}
@@ -256,6 +268,7 @@ fn complete_hook_commands() -> Vec<CompletionCandidate> {
struct BranchCompleter {
suppress_with_create: bool,
exclude_remote_only: bool,
+ worktree_only: bool,
}
impl ValueCompleter for BranchCompleter {
@@ -267,21 +280,26 @@ impl ValueCompleter for BranchCompleter {
// Filter branches by prefix - clap doesn't filter ArgValueCompleter results
let prefix = current.to_string_lossy();
- complete_branches(self.suppress_with_create, self.exclude_remote_only)
- .into_iter()
- .filter(|candidate| {
- candidate
- .get_value()
- .to_string_lossy()
- .starts_with(&*prefix)
- })
- .collect()
+ complete_branches(
+ self.suppress_with_create,
+ self.exclude_remote_only,
+ self.worktree_only,
+ )
+ .into_iter()
+ .filter(|candidate| {
+ candidate
+ .get_value()
+ .to_string_lossy()
+ .starts_with(&*prefix)
+ })
+ .collect()
}
}
fn complete_branches(
suppress_with_create: bool,
exclude_remote_only: bool,
+ worktree_only: bool,
) -> Vec<CompletionCandidate> {
if suppress_with_create && suppress_switch_branch_completion() {
return Vec::new();
@@ -299,7 +317,13 @@ fn complete_branches(
branches
.into_iter()
.filter(|branch| {
- !exclude_remote_only || !matches!(branch.category, BranchCategory::Remote(_))
+ if worktree_only {
+ matches!(branch.category, BranchCategory::Worktree)
+ } else if exclude_remote_only {
+ !matches!(branch.category, BranchCategory::Remote(_))
+ } else {
+ true
+ }
})
.map(|branch| {
let time_str = format_relative_time_short(branch.timestamp);
diff --git a/src/main.rs b/src/main.rs
index 1c48ccf2b..46dc10394 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -37,7 +37,7 @@ use commands::{
handle_list, handle_merge, handle_rebase, handle_remove, handle_remove_current,
handle_show_theme, handle_squash, handle_state_clear, handle_state_clear_all, handle_state_get,
handle_state_set, handle_state_show, handle_switch, handle_unconfigure_shell,
- resolve_worktree_arg, run_hook, step_commit, step_for_each,
+ resolve_worktree_arg, run_hook, step_commit, step_copy_ignored, step_for_each,
};
use output::{execute_user_command, handle_remove_output, handle_switch_output};
@@ -1117,6 +1117,9 @@ fn main() {
}
})
}
+ StepCommand::CopyIgnored { from, to, dry_run } => {
+ step_copy_ignored(from.as_deref(), to.as_deref(), dry_run)
+ }
StepCommand::ForEach { args } => step_for_each(args),
},
Commands::Hook { action } => match action {
diff --git a/tests/integration_tests/completion.rs b/tests/integration_tests/completion.rs
index 4f3d93183..2c6795280 100644
--- a/tests/integration_tests/completion.rs
+++ b/tests/integration_tests/completion.rs
@@ -591,11 +591,15 @@ fn test_complete_step_subcommands(repo: TestRepo) {
assert!(subcommands.contains(&"squash"), "Missing squash");
assert!(subcommands.contains(&"push"), "Missing push");
assert!(subcommands.contains(&"rebase"), "Missing rebase");
+ assert!(
+ subcommands.contains(&"copy-ignored"),
+ "Missing copy-ignored"
+ );
assert!(subcommands.contains(&"for-each"), "Missing for-each");
assert_eq!(
subcommands.len(),
- 5,
- "Should have exactly 5 step subcommands"
+ 6,
+ "Should have exactly 6 step subcommands"
);
}
diff --git a/tests/integration_tests/mod.rs b/tests/integration_tests/mod.rs
index c6c11101a..c74cddec5 100644
--- a/tests/integration_tests/mod.rs
+++ b/tests/integration_tests/mod.rs
@@ -50,5 +50,6 @@ pub mod shell_integration_windows;
pub mod shell_wrapper;
pub mod spacing_edge_cases;
pub mod statusline;
+pub mod step_copy_ignored;
pub mod switch;
pub mod user_hooks;
diff --git a/tests/integration_tests/step_copy_ignored.rs b/tests/integration_tests/step_copy_ignored.rs
new file mode 100644
index 000000000..dd495d8d2
--- /dev/null
+++ b/tests/integration_tests/step_copy_ignored.rs
@@ -0,0 +1,450 @@
+//! Integration tests for `wt step copy-ignored`
+
+use crate::common::{TestRepo, make_snapshot_cmd, repo};
+use insta_cmd::assert_cmd_snapshot;
+use rstest::rstest;
+use std::fs;
+
+/// Test with no .worktreeinclude file
+#[rstest]
+fn test_copy_ignored_no_worktreeinclude(mut repo: TestRepo) {
+ let feature_path = repo.add_worktree("feature");
+ // No .worktreeinclude file exists
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["copy-ignored"],
+ Some(&feature_path),
+ ));
+}
+
+/// Test with .worktreeinclude but nothing ignored
+#[rstest]
+fn test_copy_ignored_empty_intersection(mut repo: TestRepo) {
+ let feature_path = repo.add_worktree("feature");
+ // Create .worktreeinclude with a pattern
+ fs::write(repo.root_path().join(".worktreeinclude"), ".env\n").unwrap();
+ // But don't create .gitignore or .env file
+
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["copy-ignored"],
+ Some(&feature_path),
+ ));
+}
+
+/// Test that files in .worktreeinclude but NOT in .gitignore are not copied
+#[rstest]
+fn test_copy_ignored_not_ignored_file(mut repo: TestRepo) {
+ // Create feature worktree
+ let feature_path = repo.add_worktree("feature");
+
+ // Create .env file in main but it's not in .gitignore
+ fs::write(repo.root_path().join(".env"), "SECRET=value").unwrap();
+
+ // Create .worktreeinclude listing .env
+ fs::write(repo.root_path().join(".worktreeinclude"), ".env\n").unwrap();
+
+ // Run from feature worktree
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["copy-ignored"],
+ Some(&feature_path),
+ ));
+}
+
+/// Test basic file copy: .env in both .gitignore and .worktreeinclude
+#[rstest]
+fn test_copy_ignored_basic(mut repo: TestRepo) {
+ // Create feature worktree
+ let feature_path = repo.add_worktree("feature");
+
+ // Create .env file in main
+ fs::write(repo.root_path().join(".env"), "SECRET=value").unwrap();
+
+ // Add .env to .gitignore
+ fs::write(repo.root_path().join(".gitignore"), ".env\n").unwrap();
+
+ // Create .worktreeinclude listing .env
+ fs::write(repo.root_path().join(".worktreeinclude"), ".env\n").unwrap();
+
+ // Run from feature worktree
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["copy-ignored"],
+ Some(&feature_path),
+ ));
+
+ // Verify file was copied
+ let copied_env = feature_path.join(".env");
+ assert!(
+ copied_env.exists(),
+ ".env should be copied to feature worktree"
+ );
+ assert_eq!(
+ fs::read_to_string(&copied_env).unwrap(),
+ "SECRET=value",
+ ".env content should match"
+ );
+}
+
+/// Test idempotent behavior: running twice should succeed (skips existing files)
+#[rstest]
+fn test_copy_ignored_idempotent(mut repo: TestRepo) {
+ let feature_path = repo.add_worktree("feature");
+
+ // Setup: .env file that matches both patterns
+ fs::write(repo.root_path().join(".env"), "SECRET=value").unwrap();
+ fs::write(repo.root_path().join(".gitignore"), ".env\n").unwrap();
+ fs::write(repo.root_path().join(".worktreeinclude"), ".env\n").unwrap();
+
+ // Run copy-ignored twice - second run should succeed (skip existing)
+ let output1 = repo
+ .wt_command()
+ .args(["step", "copy-ignored"])
+ .current_dir(&feature_path)
+ .output()
+ .unwrap();
+ assert!(output1.status.success(), "First copy should succeed");
+
+ let output2 = repo
+ .wt_command()
+ .args(["step", "copy-ignored"])
+ .current_dir(&feature_path)
+ .output()
+ .unwrap();
+ assert!(
+ output2.status.success(),
+ "Second copy should succeed (idempotent)"
+ );
+
+ // File should still exist with original content
+ assert_eq!(
+ fs::read_to_string(feature_path.join(".env")).unwrap(),
+ "SECRET=value"
+ );
+}
+
+/// Test copying a single file in a subdirectory (creates parent dirs)
+#[rstest]
+fn test_copy_ignored_nested_file(mut repo: TestRepo) {
+ let feature_path = repo.add_worktree("feature");
+
+ // Create a nested file that's gitignored
+ let cache_dir = repo.root_path().join("cache");
+ fs::create_dir_all(&cache_dir).unwrap();
+ fs::write(cache_dir.join("data.json"), r#"{"key": "value"}"#).unwrap();
+
+ // Gitignore the specific file (not the directory)
+ fs::write(repo.root_path().join(".gitignore"), "cache/data.json\n").unwrap();
+
+ // Worktreeinclude the specific file
+ fs::write(
+ repo.root_path().join(".worktreeinclude"),
+ "cache/data.json\n",
+ )
+ .unwrap();
+
+ // Run from feature worktree
+ let output = repo
+ .wt_command()
+ .args(["step", "copy-ignored"])
+ .current_dir(&feature_path)
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+
+ // Verify file was copied (parent dir should be created)
+ let copied_file = feature_path.join("cache").join("data.json");
+ assert!(copied_file.exists(), "Nested file should be copied");
+ assert_eq!(
+ fs::read_to_string(&copied_file).unwrap(),
+ r#"{"key": "value"}"#
+ );
+}
+
+/// Test --dry-run shows what would be copied without copying
+#[rstest]
+fn test_copy_ignored_dry_run(mut repo: TestRepo) {
+ let feature_path = repo.add_worktree("feature");
+
+ // Setup: .env file that matches both patterns
+ fs::write(repo.root_path().join(".env"), "SECRET=value").unwrap();
+ fs::write(repo.root_path().join(".gitignore"), ".env\n").unwrap();
+ fs::write(repo.root_path().join(".worktreeinclude"), ".env\n").unwrap();
+
+ // Run with --dry-run
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["copy-ignored", "--dry-run"],
+ Some(&feature_path),
+ ));
+
+ // Verify file was NOT copied
+ let copied_env = feature_path.join(".env");
+ assert!(
+ !copied_env.exists(),
+ ".env should NOT be copied in dry-run mode"
+ );
+}
+
+/// Test copying a directory (e.g., target/)
+#[rstest]
+fn test_copy_ignored_directory(mut repo: TestRepo) {
+ let feature_path = repo.add_worktree("feature");
+
+ // Create target directory with some files
+ let target_dir = repo.root_path().join("target");
+ fs::create_dir_all(target_dir.join("debug")).unwrap();
+ fs::write(target_dir.join("debug").join("output"), "binary content").unwrap();
+ fs::write(target_dir.join("CACHEDIR.TAG"), "cache tag").unwrap();
+
+ // Add a .git file inside target (should be skipped by copy_dir_recursive)
+ fs::write(target_dir.join(".git"), "gitdir: /some/path").unwrap();
+
+ // Add target to .gitignore
+ fs::write(repo.root_path().join(".gitignore"), "target/\n").unwrap();
+
+ // Create .worktreeinclude listing target
+ fs::write(repo.root_path().join(".worktreeinclude"), "target/\n").unwrap();
+
+ // Run from feature worktree
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["copy-ignored"],
+ Some(&feature_path),
+ ));
+
+ // Verify directory was copied with contents
+ let copied_target = feature_path.join("target");
+ assert!(copied_target.exists(), "target should be copied");
+ assert!(
+ copied_target.join("debug").join("output").exists(),
+ "target/debug/output should be copied"
+ );
+ assert_eq!(
+ fs::read_to_string(copied_target.join("debug").join("output")).unwrap(),
+ "binary content"
+ );
+
+ // Verify .git was NOT copied (skipped by copy_dir_recursive)
+ assert!(
+ !copied_target.join(".git").exists(),
+ ".git should NOT be copied"
+ );
+}
+
+/// Test glob patterns: .env.*
+#[rstest]
+fn test_copy_ignored_glob_pattern(mut repo: TestRepo) {
+ let feature_path = repo.add_worktree("feature");
+
+ // Create multiple .env files
+ fs::write(repo.root_path().join(".env"), "base").unwrap();
+ fs::write(repo.root_path().join(".env.local"), "local").unwrap();
+ fs::write(repo.root_path().join(".env.test"), "test").unwrap();
+
+ // .gitignore with .env*
+ fs::write(repo.root_path().join(".gitignore"), ".env*\n").unwrap();
+
+ // .worktreeinclude with same pattern
+ fs::write(repo.root_path().join(".worktreeinclude"), ".env*\n").unwrap();
+
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["copy-ignored"],
+ Some(&feature_path),
+ ));
+
+ // Verify all were copied
+ assert!(feature_path.join(".env").exists());
+ assert!(feature_path.join(".env.local").exists());
+ assert!(feature_path.join(".env.test").exists());
+}
+
+/// Test same worktree source and destination
+#[rstest]
+fn test_copy_ignored_same_worktree(repo: TestRepo) {
+ // Setup files
+ fs::write(repo.root_path().join(".env"), "value").unwrap();
+ fs::write(repo.root_path().join(".gitignore"), ".env\n").unwrap();
+ fs::write(repo.root_path().join(".worktreeinclude"), ".env\n").unwrap();
+
+ // Run from main worktree (source = dest = main)
+ assert_cmd_snapshot!(make_snapshot_cmd(&repo, "step", &["copy-ignored"], None,));
+}
+
+/// Test --from flag to specify source worktree
+#[rstest]
+fn test_copy_ignored_from_flag(mut repo: TestRepo) {
+ // Create two worktrees
+ let feature_a = repo.add_worktree("feature-a");
+ let feature_b = repo.add_worktree("feature-b");
+
+ // Create .env in feature-a (not in main)
+ fs::write(feature_a.join(".env"), "from-feature-a").unwrap();
+
+ // Add .env to .gitignore in feature-a (source worktree)
+ fs::write(feature_a.join(".gitignore"), ".env\n").unwrap();
+
+ // Create .worktreeinclude in feature-a
+ fs::write(feature_a.join(".worktreeinclude"), ".env\n").unwrap();
+
+ // Run from feature-b, copying from feature-a
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["copy-ignored", "--from", "feature-a"],
+ Some(&feature_b),
+ ));
+
+ // Verify file was copied
+ assert!(feature_b.join(".env").exists());
+ assert_eq!(
+ fs::read_to_string(feature_b.join(".env")).unwrap(),
+ "from-feature-a"
+ );
+}
+
+/// Test that COW copies are independent (modifying one doesn't affect the other)
+#[rstest]
+fn test_copy_ignored_cow_independence(mut repo: TestRepo) {
+ let feature_path = repo.add_worktree("feature");
+
+ // Create file in main
+ fs::write(repo.root_path().join(".env"), "original").unwrap();
+ fs::write(repo.root_path().join(".gitignore"), ".env\n").unwrap();
+ fs::write(repo.root_path().join(".worktreeinclude"), ".env\n").unwrap();
+
+ // Copy to feature
+ repo.wt_command()
+ .args(["step", "copy-ignored"])
+ .current_dir(&feature_path)
+ .output()
+ .expect("copy-ignored should succeed");
+
+ // Modify the copy in feature
+ fs::write(feature_path.join(".env"), "modified").unwrap();
+
+ // Original should be unchanged
+ assert_eq!(
+ fs::read_to_string(repo.root_path().join(".env")).unwrap(),
+ "original",
+ "Original file should be unchanged after modifying copy"
+ );
+}
+
+/// Test deep file patterns: **/.claude/settings.local.json
+#[rstest]
+fn test_copy_ignored_deep_pattern(mut repo: TestRepo) {
+ let feature_path = repo.add_worktree("feature");
+
+ // Create nested .claude directory with settings
+ let claude_dir = repo.root_path().join(".claude");
+ fs::create_dir_all(&claude_dir).unwrap();
+ fs::write(claude_dir.join("settings.local.json"), r#"{"key":"value"}"#).unwrap();
+
+ // Add to .gitignore
+ fs::write(
+ repo.root_path().join(".gitignore"),
+ "**/.claude/settings.local.json\n",
+ )
+ .unwrap();
+
+ // Add to .worktreeinclude
+ fs::write(
+ repo.root_path().join(".worktreeinclude"),
+ "**/.claude/settings.local.json\n",
+ )
+ .unwrap();
+
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["copy-ignored"],
+ Some(&feature_path),
+ ));
+
+ // Verify the nested file was copied
+ assert!(
+ feature_path
+ .join(".claude")
+ .join("settings.local.json")
+ .exists()
+ );
+}
+
+/// Test that nested .gitignore files are respected (not just root .gitignore)
+#[rstest]
+fn test_copy_ignored_nested_gitignore(mut repo: TestRepo) {
+ let feature_path = repo.add_worktree("feature");
+
+ // Create a subdirectory with its own .gitignore
+ let subdir = repo.root_path().join("config");
+ fs::create_dir_all(&subdir).unwrap();
+
+ // Create a file ignored by the nested .gitignore (not root)
+ fs::write(subdir.join("local.json"), r#"{"local":true}"#).unwrap();
+
+ // Add .gitignore ONLY in the subdirectory
+ fs::write(subdir.join(".gitignore"), "local.json\n").unwrap();
+
+ // Root .worktreeinclude should match the file
+ fs::write(
+ repo.root_path().join(".worktreeinclude"),
+ "config/local.json\n",
+ )
+ .unwrap();
+
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["copy-ignored"],
+ Some(&feature_path),
+ ));
+
+ // Verify the file was copied (nested .gitignore was respected)
+ assert!(
+ feature_path.join("config").join("local.json").exists(),
+ "File ignored by nested .gitignore should be copied"
+ );
+}
+
+/// Test --to flag to specify destination worktree
+#[rstest]
+fn test_copy_ignored_to_flag(mut repo: TestRepo) {
+ // Create two worktrees
+ let feature_a = repo.add_worktree("feature-a");
+ let feature_b = repo.add_worktree("feature-b");
+
+ // Create .env in main
+ fs::write(repo.root_path().join(".env"), "from-main").unwrap();
+
+ // Add .env to .gitignore in main
+ fs::write(repo.root_path().join(".gitignore"), ".env\n").unwrap();
+
+ // Create .worktreeinclude in main
+ fs::write(repo.root_path().join(".worktreeinclude"), ".env\n").unwrap();
+
+ // Run from feature-a, copying from main (default) to feature-b (explicit)
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["copy-ignored", "--to", "feature-b"],
+ Some(&feature_a),
+ ));
+
+ // Verify file was copied to feature-b (not feature-a)
+ assert!(feature_b.join(".env").exists());
+ assert!(!feature_a.join(".env").exists());
+ assert_eq!(
+ fs::read_to_string(feature_b.join(".env")).unwrap(),
+ "from-main"
+ );
+}
diff --git a/tests/snapshots/integration__integration_tests__help__help_step_long.snap b/tests/snapshots/integration__integration_tests__help__help_step_long.snap
index c59ff2efc..44b4eb341 100644
--- a/tests/snapshots/integration__integration_tests__help__help_step_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_step_long.snap
@@ -25,11 +25,12 @@ wt step - Run individual operations
Usage: wt step [OPTIONS] <COMMAND>
Commands:
- commit Commit changes with LLM commit message
- squash Squash commits since branching
- push Fast-forward target to current branch
- rebase Rebase onto target
- for-each [experimental] Run command in each worktree
+ commit Commit changes with LLM commit message
+ squash Squash commits since branching
+ push Fast-forward target to current branch
+ rebase Rebase onto target
+ copy-ignored Copy .worktreeinclude files to another worktree
+ for-each [experimental] Run command in each worktree
Options:
-h, --help
@@ -67,6 +68,7 @@ Manual merge workflow with review between steps:
- squash — Squash all branch commits into one with LLM-generated message
- rebase — Rebase onto target branch
- push — Fast-forward target to current branch
+- copy-ignored — Copy files listed in .worktreeinclude
- for-each — [experimental] Run a command in every worktree
Options
diff --git a/tests/snapshots/integration__integration_tests__help__help_step_short.snap b/tests/snapshots/integration__integration_tests__help__help_step_short.snap
index 4f9466ca2..33402c083 100644
--- a/tests/snapshots/integration__integration_tests__help__help_step_short.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_step_short.snap
@@ -25,11 +25,12 @@ wt step - Run individual operations
Usage: wt step [OPTIONS] <COMMAND>
Commands:
- commit Commit changes with LLM commit message
- squash Squash commits since branching
- push Fast-forward target to current branch
- rebase Rebase onto target
- for-each [experimental] Run command in each worktree
+ commit Commit changes with LLM commit message
+ squash Squash commits since branching
+ push Fast-forward target to current branch
+ rebase Rebase onto target
+ copy-ignored Copy .worktreeinclude files to another worktree
+ for-each [experimental] Run command in each worktree
Options:
-h, --help Print help (see more with '--help')
diff --git a/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_basic.snap b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_basic.snap
new file mode 100644
index 000000000..b2aaf1e7c
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_basic.snap
@@ -0,0 +1,35 @@
+---
+source: tests/integration_tests/step_copy_ignored.rs
+info:
+ program: wt
+ args:
+ - step
+ - copy-ignored
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✓ Copied 1 entry
diff --git a/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_deep_pattern.snap b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_deep_pattern.snap
new file mode 100644
index 000000000..b2aaf1e7c
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_deep_pattern.snap
@@ -0,0 +1,35 @@
+---
+source: tests/integration_tests/step_copy_ignored.rs
+info:
+ program: wt
+ args:
+ - step
+ - copy-ignored
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✓ Copied 1 entry
diff --git a/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_directory.snap b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_directory.snap
new file mode 100644
index 000000000..b2aaf1e7c
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_directory.snap
@@ -0,0 +1,35 @@
+---
+source: tests/integration_tests/step_copy_ignored.rs
+info:
+ program: wt
+ args:
+ - step
+ - copy-ignored
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✓ Copied 1 entry
diff --git a/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_dry_run.snap b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_dry_run.snap
new file mode 100644
index 000000000..5f11754f3
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_dry_run.snap
@@ -0,0 +1,37 @@
+---
+source: tests/integration_tests/step_copy_ignored.rs
+info:
+ program: wt
+ args:
+ - step
+ - copy-ignored
+ - "--dry-run"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ Would copy 1 entry:
+  .env (file)
diff --git a/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_empty_intersection.snap b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_empty_intersection.snap
new file mode 100644
index 000000000..be466b678
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_empty_intersection.snap
@@ -0,0 +1,35 @@
+---
+source: tests/integration_tests/step_copy_ignored.rs
+info:
+ program: wt
+ args:
+ - step
+ - copy-ignored
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ No matching files to copy
diff --git a/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_from_flag.snap b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_from_flag.snap
new file mode 100644
index 000000000..32412034e
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_from_flag.snap
@@ -0,0 +1,37 @@
+---
+source: tests/integration_tests/step_copy_ignored.rs
+info:
+ program: wt
+ args:
+ - step
+ - copy-ignored
+ - "--from"
+ - feature-a
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✓ Copied 1 entry
diff --git a/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_glob_pattern.snap b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_glob_pattern.snap
new file mode 100644
index 000000000..27a6fe5e6
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_glob_pattern.snap
@@ -0,0 +1,35 @@
+---
+source: tests/integration_tests/step_copy_ignored.rs
+info:
+ program: wt
+ args:
+ - step
+ - copy-ignored
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✓ Copied 3 entries
diff --git a/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_nested_gitignore.snap b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_nested_gitignore.snap
new file mode 100644
index 000000000..b2aaf1e7c
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_nested_gitignore.snap
@@ -0,0 +1,35 @@
+---
+source: tests/integration_tests/step_copy_ignored.rs
+info:
+ program: wt
+ args:
+ - step
+ - copy-ignored
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✓ Copied 1 entry
diff --git a/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_no_worktreeinclude.snap b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_no_worktreeinclude.snap
new file mode 100644
index 000000000..7053e034e
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_no_worktreeinclude.snap
@@ -0,0 +1,35 @@
+---
+source: tests/integration_tests/step_copy_ignored.rs
+info:
+ program: wt
+ args:
+ - step
+ - copy-ignored
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ No .worktreeinclude file found
diff --git a/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_not_ignored_file.snap b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_not_ignored_file.snap
new file mode 100644
index 000000000..be466b678
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_not_ignored_file.snap
@@ -0,0 +1,35 @@
+---
+source: tests/integration_tests/step_copy_ignored.rs
+info:
+ program: wt
+ args:
+ - step
+ - copy-ignored
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ No matching files to copy
diff --git a/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_same_worktree.snap b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_same_worktree.snap
new file mode 100644
index 000000000..573f58fdd
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_same_worktree.snap
@@ -0,0 +1,35 @@
+---
+source: tests/integration_tests/step_copy_ignored.rs
+info:
+ program: wt
+ args:
+ - step
+ - copy-ignored
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ Source and destination are the same worktree
diff --git a/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_to_flag.snap b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_to_flag.snap
new file mode 100644
index 000000000..8f2989eb6
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_copy_ignored__copy_ignored_to_flag.snap
@@ -0,0 +1,37 @@
+---
+source: tests/integration_tests/step_copy_ignored.rs
+info:
+ program: wt
+ args:
+ - step
+ - copy-ignored
+ - "--to"
+ - feature-b
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✓ Copied 1 entry