Skip to content

Commit 18016ff

Browse files
committed
refactor: simplify to menu-only interface with comprehensive docs and fixes
1 parent 71b83f1 commit 18016ff

30 files changed

Lines changed: 3754 additions & 1179 deletions

.git-workers.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Git Workers configuration file
2+
3+
[repository]
4+
# Repository URL for identification (optional)
5+
# This ensures hooks only run in the intended repository
6+
url = "https://github.com/wasabeef/git-workers.git"
7+
8+
[hooks]
9+
# Run after creating a new worktree
10+
post-create = [
11+
"echo '🤖 Created worktree: {{worktree_name}}'",
12+
"echo '🤖 Path: {{worktree_path}}'"
13+
]
14+
15+
# Run before removing a worktree
16+
pre-remove = [
17+
"echo '🤖 Removing worktree: {{worktree_name}}'"
18+
]
19+
20+
# Run after switching to a worktree
21+
post-switch = [
22+
"echo 'S🤖 witched to: {{worktree_name}}'"
23+
]

CHANGELOG.md

Lines changed: 80 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,86 @@
11
# Changelog
22

3-
Please see [GitHub Releases](https://github.com/wasabeef/git-workers/releases) for the complete changelog.
3+
All notable changes to Git Workers will be documented in this file.
44

5-
Each release includes:
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
67

7-
- Detailed release notes generated from commit history
8-
- Binary downloads for all supported platforms
9-
- Installation instructions
8+
For detailed release notes and binary downloads, see [GitHub Releases](https://github.com/wasabeef/git-workers/releases).
109

11-
The release notes are automatically generated using conventional commits, categorizing changes into:
10+
## [Unreleased]
1211

13-
- Features
14-
- Bug Fixes
15-
- Documentation
16-
- Performance improvements
17-
- And more
12+
### Changed
13+
14+
- **BREAKING**: Removed command-line argument options (--list, --create, etc.) in favor of interactive menu-only interface
15+
- Simplified main.rs to focus solely on interactive menu operations
16+
- Improved worktree rename functionality with `git worktree repair` integration
17+
- Enhanced configuration lookup strategy:
18+
- Now checks current directory first (useful for bare repo worktrees)
19+
- Then checks parent directory's main/master worktree
20+
- Finally falls back to repository root
21+
- Improved path handling for worktree creation:
22+
- Paths are now canonicalized to eliminate "../" in display
23+
- "In subdirectory" option now correctly creates worktrees in subdirectories
24+
25+
### Added
26+
27+
- Edit hooks menu option (`λ`) for managing lifecycle hooks through the interface
28+
- Comprehensive Rustdoc documentation for all modules and functions
29+
- Current directory configuration lookup priority for .git-workers.toml
30+
- Parent directory configuration lookup for .git-workers.toml
31+
- Better error handling with mutex poison recovery in tests
32+
- Branch deletion functionality in batch delete operations
33+
- Orphaned branch detection when deleting worktrees
34+
- Repository URL validation in configuration files
35+
- New test files for batch delete and edit hooks functionality
36+
37+
### Fixed
38+
39+
- All clippy warnings resolved:
40+
- manual_div_ceil replaced with div_ceil() method
41+
- manual_unwrap_or patterns simplified
42+
- needless_borrows in format! macros removed
43+
- useless_vec replaced with arrays
44+
- manual_flatten replaced with .flatten() method
45+
- Test failures related to parent directory configuration search
46+
- ESC cancellation pattern tests updated for new code style
47+
- Worktree rename test expectations aligned with Git limitations
48+
- "In subdirectory" option now correctly creates worktrees in worktrees/ folder
49+
- Path display now shows clean canonical paths without "../"
50+
- Batch delete now properly deletes orphaned branches
51+
- Edit hooks no longer incorrectly identifies regular repos as bare
52+
53+
### Documentation
54+
55+
- Updated README.md with current features and usage:
56+
- Added configuration file lookup priority documentation
57+
- Updated worktree pattern examples
58+
- Added custom path creation examples
59+
- Added repository URL configuration example
60+
- Clarified batch delete branch deletion functionality
61+
- Enhanced CLAUDE.md with architectural details and development commands
62+
- Added detailed inline documentation for all public APIs
63+
- Updated all Rustdoc comments to reflect recent changes
64+
65+
## [0.1.0] - 2024-12-17
66+
67+
### Added
68+
69+
- Initial release of Git Workers
70+
- Interactive menu-driven interface for Git worktree management
71+
- List worktrees with detailed status information (branch, changes, ahead/behind)
72+
- Fuzzy search through worktrees with real-time filtering
73+
- Create new worktrees from branches or HEAD
74+
- Delete single or multiple worktrees with safety checks
75+
- Switch worktrees with automatic directory change via shell integration
76+
- Rename worktrees and optionally their branches
77+
- Cleanup old worktrees by age
78+
- Hook system for lifecycle events (post-create, pre-remove, post-switch)
79+
- Shell integration for Bash and Zsh
80+
- Configuration file support (.git-workers.toml)
81+
- Template variable support in hooks ({{worktree_name}}, {{worktree_path}})
82+
- Worktree pattern detection for organized directory structure
83+
- ESC key support for cancelling operations
84+
- Colored terminal output with theme support
85+
- Progress indicators for long operations
86+
- Homebrew installation support

CLAUDE.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## Project Overview
66

7-
Git Workers is an interactive CLI tool for managing Git worktrees, written in Rust. It provides a menu-driven interface for creating, deleting, switching, and renaming worktrees, with shell integration for automatic directory switching.
7+
Git Workers is an interactive CLI tool for managing Git worktrees, written in Rust. It provides a menu-driven interface for creating, deleting, switching, and renaming worktrees, with shell integration for automatic directory switching. The tool focuses on simplicity and user experience, offering only interactive menu-based operations without command-line arguments (except for --version and --help).
88

99
## Development Commands
1010

@@ -100,26 +100,44 @@ Automatic directory switching on worktree change requires special implementation
100100
Define lifecycle hooks in `.git-workers.toml`:
101101

102102
```toml
103+
[repository]
104+
# Optional: Repository URL validation
105+
url = "https://github.com/owner/repo.git"
106+
103107
[hooks]
104108
post-create = ["npm install", "cp .env.example .env"]
105109
pre-remove = ["rm -rf node_modules"]
106110
post-switch = ["echo 'Switched to {{worktree_name}}'"]
107111
```
108112

109113
Template variables:
110-
111114
- `{{worktree_name}}`: The worktree name
112115
- `{{worktree_path}}`: Absolute path to worktree
113116

117+
### Configuration File Loading
118+
119+
Configuration is loaded in priority order:
120+
1. Current directory (useful for bare repo worktrees)
121+
2. Parent directory's main/master worktree
122+
3. Repository root
123+
124+
This flexible strategy ensures hooks work in both regular and bare repositories.
125+
114126
### Worktree Patterns
115127

116128
First worktree creation offers two options:
117-
118129
1. Same level as repository: `../worktree-name`
119-
2. In subdirectory (recommended): `../repo/worktrees/worktree-name`
130+
2. In subdirectory (recommended): `repo/worktrees/worktree-name`
120131

121132
Subsequent worktrees follow the established pattern automatically.
122133

134+
### Path Handling
135+
136+
- Paths starting with `../` create worktrees at repository parent level
137+
- Paths containing `/` (e.g., `worktrees/feature`) create within repository
138+
- Simple names use pattern detection from existing worktrees
139+
- All paths are canonicalized to eliminate `../` in display
140+
123141
### ESC Key Handling
124142

125143
All interactive prompts support ESC cancellation through custom `input_esc_raw` module:
@@ -131,11 +149,21 @@ All interactive prompts support ESC cancellation through custom `input_esc_raw`
131149
### Worktree Rename Implementation
132150

133151
Since Git lacks native rename functionality:
134-
135152
1. Move directory with `fs::rename`
136153
2. Update `.git/worktrees/<name>` metadata directory
137154
3. Update gitdir files in both directions
138-
4. Optionally rename associated branch if it matches worktree name
155+
4. Run `git worktree repair` to update Git's tracking
156+
5. Optionally rename associated branch if it matches worktree name
157+
158+
Note: Due to Git limitations, the worktree will still be tracked with its original name internally, but the directory will be renamed.
159+
160+
### Batch Delete Features
161+
162+
- Multi-select interface for choosing multiple worktrees
163+
- Automatic detection of orphaned branches (using `is_branch_unique_to_worktree`)
164+
- Separate confirmations for worktree and branch deletion
165+
- Executes pre-remove hooks for each worktree
166+
- Reports success/failure counts separately for worktrees and branches
139167

140168
### CI/CD Configuration
141169

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ chrono = "0.4"
3737
fuzzy-matcher = "0.3"
3838
indicatif = "0.17"
3939
rustyline = "14.0"
40+
unicode-width = "0.2.1"
4041

4142
[dev-dependencies]
4243
tempfile = "3.8"

README.md

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ https://github.com/user-attachments/assets/bb58444f-4936-411c-be51-62faf08fe9a0
99

1010
## Features
1111

12-
- 📋 List worktrees with status information
12+
- 📋 List worktrees with detailed status information (branch, changes, ahead/behind)
1313
- 🔍 Fuzzy search through worktrees
1414
- ➕ Create new worktrees from branches or HEAD
1515
- ➖ Delete single or multiple worktrees
1616
- 🔄 Switch worktrees with automatic directory change
1717
- ✏️ Rename worktrees and optionally their branches
1818
- 🧹 Cleanup old worktrees by age
1919
- 🪝 Execute hooks on worktree lifecycle events
20+
- 📝 Edit and manage hooks through the interface
2021

2122
## Installation
2223

@@ -26,6 +27,14 @@ https://github.com/user-attachments/assets/bb58444f-4936-411c-be51-62faf08fe9a0
2627
brew install wasabeef/gw-tap/gw
2728
```
2829

30+
### From Source
31+
32+
```bash
33+
git clone https://github.com/wasabeef/git-workers.git
34+
cd git-workers
35+
cargo install --path .
36+
```
37+
2938
### Shell Integration
3039

3140
To enable automatic directory switching when switching worktrees, add this to your shell config:
@@ -35,6 +44,12 @@ To enable automatic directory switching when switching worktrees, add this to yo
3544
source $(brew --prefix)/share/gw/shell/gw.sh
3645
```
3746

47+
For manual installation, use the path where git-workers is installed:
48+
49+
```bash
50+
source /path/to/git-workers/shell/gw.sh
51+
```
52+
3853
## Usage
3954

4055
Run `gw` in any Git repository:
@@ -43,18 +58,84 @@ Run `gw` in any Git repository:
4358
gw
4459
```
4560

46-
### Menu Options
61+
### Interactive Menu
62+
63+
Git Workers provides an interactive menu-driven interface. Simply run `gw` and navigate through the options:
4764

48-
- **List worktrees** (``): Display all worktrees with status information
49-
- **Search worktrees** (`?`): Fuzzy search through worktrees
50-
- **Create worktree** (`+`): Create a new worktree
51-
- **Delete worktree** (`-`): Delete a single worktree
52-
- **Batch delete** (`=`): Delete multiple worktrees at once
65+
- **List worktrees** (``): Display all worktrees with branch, changes, and sync status
66+
- **Search worktrees** (`?`): Fuzzy search through worktree names and branches
67+
- **Create worktree** (`+`): Create a new worktree from existing branch or create a new branch
68+
- **Delete worktree** (`-`): Delete a single worktree with safety checks
69+
- **Batch delete** (`=`): Select and delete multiple worktrees at once (optionally deletes orphaned branches)
5370
- **Cleanup old worktrees** (`~`): Remove worktrees older than specified days
54-
- **Switch worktree** (``): Switch to another worktree (changes directory)
55-
- **Rename worktree** (`*`): Rename an existing worktree
71+
- **Switch worktree** (``): Switch to another worktree (automatically changes directory)
72+
- **Rename worktree** (`*`): Rename worktree directory and optionally its branch
73+
- **Edit hooks** (`λ`): Configure lifecycle hooks in `.git-workers.toml`
5674
- **Exit** (`x`): Exit the application
5775

76+
### Configuration
77+
78+
Git Workers uses `.git-workers.toml` for configuration. The file is loaded from (in order of priority):
79+
1. Current directory (useful for bare repository worktrees)
80+
2. Parent directory's main/master worktree (for organized worktree structures)
81+
3. Repository root
82+
83+
```toml
84+
[repository]
85+
# Optional: Specify repository URL to ensure hooks only run in the intended repository
86+
# url = "https://github.com/owner/repo.git"
87+
88+
[hooks]
89+
# Execute after creating a new worktree
90+
post-create = [
91+
"npm install",
92+
"cp .env.example .env",
93+
"echo 'Worktree {{worktree_name}} created at {{worktree_path}}'"
94+
]
95+
96+
# Execute before removing a worktree
97+
pre-remove = [
98+
"echo 'Cleaning up {{worktree_name}}'",
99+
"rm -rf node_modules"
100+
]
101+
102+
# Execute after switching to a worktree
103+
post-switch = [
104+
"echo 'Switched to {{worktree_name}}'"
105+
]
106+
```
107+
108+
### Hook Variables
109+
110+
- `{{worktree_name}}`: The name of the worktree
111+
- `{{worktree_path}}`: The absolute path to the worktree
112+
113+
### Worktree Patterns
114+
115+
When creating your first worktree, Git Workers offers two patterns:
116+
117+
1. **Same level as repository**: Creates worktrees as siblings to your main repository
118+
```
119+
parent/
120+
├── my-repo/
121+
├── feature-1/
122+
└── feature-2/
123+
```
124+
125+
2. **In subdirectory** (recommended): Organizes worktrees in a dedicated directory
126+
```
127+
parent/
128+
└── my-repo/
129+
└── worktrees/
130+
├── feature-1/
131+
└── feature-2/
132+
```
133+
134+
You can also create worktrees with custom paths:
135+
- `../feature`: Creates at the same level as the repository
136+
- `worktrees/feature`: Creates in a subdirectory
137+
- `branch/feature`: Creates in a custom subdirectory structure
138+
58139
### Keyboard Shortcuts
59140

60141
- **ESC**: Cancel current operation and return to menu

0 commit comments

Comments
 (0)