Skip to content

Commit a81135b

Browse files
authored
Merge pull request #1 from wasabeef/feat-copy-files
2 parents bd9996a + 5449dc2 commit a81135b

22 files changed

Lines changed: 1557 additions & 198 deletions

.git-workers.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@ pre-remove = [
2121
post-switch = [
2222
"echo '🤖 Switched to: {{worktree_name}}'"
2323
]
24+
25+
[files]
26+
# Optional: Specify a custom source directory
27+
# If not specified, automatically finds the main worktree
28+
# source = "/path/to/custom/source"
29+
# source = "./templates" # Relative to repository root
30+
31+
# Files to copy when creating new worktrees
32+
copy = [
33+
".env",
34+
".env.local"
35+
]

CLAUDE.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ source /path/to/git-workers/shell/gw.sh
6969

7070
## Recent Changes
7171

72+
### v0.3.0 File Copy Feature
73+
74+
- Automatically copy gitignored files (like `.env`) from main worktree to new worktrees
75+
- Configurable via `[files]` section in `.git-workers.toml`
76+
- Security validation to prevent path traversal attacks
77+
- Follows same discovery priority as configuration files
78+
7279
### Branch Option Simplification
7380

7481
- Reduced from 3 options to 2: "Create from current HEAD" and "Select branch (smart mode)"
@@ -79,6 +86,7 @@ source /path/to/git-workers/shell/gw.sh
7986
- **`get_branch_worktree_map()`**: Maps branch names to worktree names, including main worktree detection
8087
- **`list_all_branches()`**: Returns both local and remote branches (remote without "origin/" prefix)
8188
- **`create_worktree_with_new_branch()`**: Creates worktree with new branch from base branch (supports git-flow style workflows)
89+
- **`copy_configured_files()`**: Copies files specified in config to new worktrees
8290

8391
## Architecture
8492

@@ -96,6 +104,7 @@ src/
96104
├── repository_info.rs # Repository information display
97105
├── input_esc_raw.rs # Custom input handling with ESC support
98106
├── constants.rs # Centralized constants (strings, formatting)
107+
├── file_copy.rs # File copy functionality for gitignored files
99108
└── utils.rs # Common utilities (error display, etc.)
100109
```
101110

@@ -194,7 +203,7 @@ Since Git lacks native rename functionality:
194203
1. Current directory (current worktree)
195204
2. Main/master worktree directories (fallback)
196205

197-
## v0.3.0 File Copy Feature (Planning)
206+
## v0.3.0 File Copy Feature (Implemented)
198207

199208
### Overview
200209

@@ -209,15 +218,18 @@ copy = [".env", ".env.local", "config/local.json"]
209218

210219
# Optional: source directory (defaults to main worktree)
211220
# source = "path/to/source"
212-
213-
# Optional: destination directory (defaults to worktree root)
214-
# destination = "path/to/dest"
215221
```
216222

217-
### Implementation Plan
218-
219-
1. **Config Structure**: Add `FilesConfig` struct with `copy`, `source`, and `destination` fields
220-
2. **File Detection**: Find main worktree directory for source files
221-
3. **Copy Logic**: In `post-create` hook phase, copy specified files
222-
4. **Error Handling**: Warn on missing files but don't fail worktree creation
223-
5. **Security**: Validate paths to prevent directory traversal attacks
223+
### Implementation Details
224+
225+
1. **Config Structure**: `FilesConfig` struct with `copy` and `source` fields (destination is always worktree root)
226+
2. **File Detection**: Uses same priority as config file discovery for finding source files
227+
3. **Copy Logic**: Executes after worktree creation but before post-create hooks
228+
4. **Error Handling**: Warns on missing files but continues with worktree creation
229+
5. **Security**: Validates paths to prevent directory traversal attacks
230+
6. **Features**:
231+
- Supports both files and directories
232+
- Recursive directory copying
233+
- Symlink detection with warnings
234+
- Maximum directory depth limit (50 levels)
235+
- Preserves file permissions

Cargo.lock

Lines changed: 3 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ path = "src/main.rs"
1919
git2 = { version = "0.20", features = ["vendored-openssl"] }
2020

2121
# CLI Framework
22-
dialoguer = "0.11"
22+
dialoguer = { version = "0.11", features = ["fuzzy-select"] }
2323
console = "0.15"
2424
clap = { version = "4.5", features = ["derive"] }
2525

@@ -31,7 +31,7 @@ toml = "0.8"
3131
anyhow = "1.0"
3232

3333
# Utility
34-
colored = "2.1" # Keep at 2.1 to maintain lower MSRV
34+
colored = "3.0"
3535
chrono = "0.4"
3636
fuzzy-matcher = "0.3"
3737
indicatif = "0.17"

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ pre-remove = [
117117
post-switch = [
118118
"echo '🤖 Switched to: {{worktree_name}}'"
119119
]
120+
121+
[files]
122+
# Optional: Specify a custom source directory
123+
# If not specified, automatically finds the main worktree
124+
# source = "/path/to/custom/source"
125+
# source = "./templates" # Relative to repository root
126+
127+
# Files to copy when creating new worktrees
128+
# These are typically gitignored files needed for development
129+
copy = [
130+
".env",
131+
".env.local"
132+
]
120133
```
121134

122135
### Hook Variables

0 commit comments

Comments
 (0)