Skip to content

Commit bd9996a

Browse files
committed
fix: hook management
1 parent 075a288 commit bd9996a

File tree

9 files changed

+293
-122
lines changed

9 files changed

+293
-122
lines changed

CLAUDE.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,42 @@ Since Git lacks native rename functionality:
182182
- Shell integration supports Bash/Zsh only
183183
- No Windows support (macOS and Linux only)
184184
- Recent breaking change: CLI arguments removed in favor of menu-only interface
185+
186+
### Configuration Loading Priority
187+
188+
**Bare repositories:**
189+
190+
- Check main/master worktree directories only
191+
192+
**Non-bare repositories:**
193+
194+
1. Current directory (current worktree)
195+
2. Main/master worktree directories (fallback)
196+
197+
## v0.3.0 File Copy Feature (Planning)
198+
199+
### Overview
200+
201+
Automatically copy ignored files (like `.env`) from main worktree to new worktrees during creation.
202+
203+
### Configuration
204+
205+
```toml
206+
[files]
207+
# Files to copy when creating new worktrees
208+
copy = [".env", ".env.local", "config/local.json"]
209+
210+
# Optional: source directory (defaults to main worktree)
211+
# source = "path/to/source"
212+
213+
# Optional: destination directory (defaults to worktree root)
214+
# destination = "path/to/dest"
215+
```
216+
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

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "git-workers"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
edition = "2021"
55
authors = ["Daichi Furiya"]
66
description = "Interactive Git worktree manager with shell integration"

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,24 @@ Git Workers provides an interactive menu-driven interface. Simply run `gw` and n
7272

7373
### Configuration
7474

75-
Git Workers uses `.git-workers.toml` for configuration. The file is loaded from (in order of priority):
75+
Git Workers uses `.git-workers.toml` for configuration. The loading strategy differs between bare and non-bare repositories:
7676

77-
1. Current directory (useful for bare repository worktrees)
78-
2. Parent directory's main/master worktree (for organized worktree structures)
79-
3. Repository root
77+
#### Bare Repositories
78+
79+
For bare repositories (e.g., `repo.git`), configuration is loaded from:
80+
81+
1. Current directory
82+
2. Default branch directory in current directory (e.g., `./main/.git-workers.toml`)
83+
3. Detected worktree pattern (automatically finds where existing worktrees are organized)
84+
4. Common subdirectories (`branch/`, `worktrees/`)
85+
86+
#### Non-bare Repositories
87+
88+
For regular repositories, configuration is loaded from:
89+
90+
1. Current directory
91+
2. Main repository directory (where `.git` is a directory)
92+
3. Parent directories' `main/` or `master/` subdirectories
8093

8194
```toml
8295
[repository]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "git-workers",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"description": "Interactive Git worktree manager",
55
"repository": {
66
"type": "git",

src/commands.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use indicatif::{ProgressBar, ProgressStyle};
2727
use std::time::Duration;
2828
use unicode_width::UnicodeWidthStr;
2929

30-
use crate::constants::{section_header, GIT_REMOTE_PREFIX, WORKTREES_SUBDIR};
30+
use crate::constants::{section_header, CONFIG_FILE_NAME, GIT_REMOTE_PREFIX, WORKTREES_SUBDIR};
3131
use crate::git::{GitWorktreeManager, WorktreeInfo};
3232
use crate::hooks::{self, HookContext};
3333
use crate::input_esc_raw::{
@@ -1789,8 +1789,8 @@ pub fn edit_hooks() -> Result<()> {
17891789
// Check if we're in a worktree structure like /path/to/repo/branch/worktree-name
17901790
if let Some(parent) = cwd.parent() {
17911791
// Look for main or master directories in the parent
1792-
let main_path = parent.join("main").join(".git-workers.toml");
1793-
let master_path = parent.join("master").join(".git-workers.toml");
1792+
let main_path = parent.join("main").join(CONFIG_FILE_NAME);
1793+
let master_path = parent.join("master").join(CONFIG_FILE_NAME);
17941794

17951795
if main_path.exists() {
17961796
main_path
@@ -1801,7 +1801,7 @@ pub fn edit_hooks() -> Result<()> {
18011801
let workdir = repo
18021802
.workdir()
18031803
.ok_or_else(|| anyhow::anyhow!("No working directory"))?;
1804-
workdir.join(".git-workers.toml")
1804+
workdir.join(CONFIG_FILE_NAME)
18051805
}
18061806
} else {
18071807
// No parent directory, use workdir
@@ -1830,7 +1830,7 @@ pub fn edit_hooks() -> Result<()> {
18301830
println!();
18311831

18321832
let create = Confirm::with_theme(&get_theme())
1833-
.with_prompt("Create .git-workers.toml?")
1833+
.with_prompt(format!("Create {}?", CONFIG_FILE_NAME))
18341834
.default(true)
18351835
.interact_opt()?
18361836
.unwrap_or(false);
@@ -1863,7 +1863,7 @@ post-switch = [
18631863
"#;
18641864

18651865
std::fs::write(&config_path, template)?;
1866-
utils::print_success("Created .git-workers.toml with template");
1866+
utils::print_success(&format!("Created {} with template", CONFIG_FILE_NAME));
18671867
} else {
18681868
return Ok(());
18691869
}

0 commit comments

Comments
 (0)