Skip to content

Commit 5251a16

Browse files
committed
feat: simplify branch selection with smart conflict resolution
1 parent ddee056 commit 5251a16

10 files changed

Lines changed: 578 additions & 99 deletions

CLAUDE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ cargo check --all-features
5454
cargo doc --no-deps --open
5555
```
5656

57+
5758
### Installation
5859

5960
```bash
@@ -67,13 +68,25 @@ cargo install --path .
6768
source /path/to/git-workers/shell/gw.sh
6869
```
6970

71+
## Recent Changes
72+
73+
### Branch Option Simplification
74+
- Reduced from 3 options to 2: "Create from current HEAD" and "Select branch (smart mode)"
75+
- Smart mode automatically handles branch conflicts and offers appropriate actions
76+
77+
### Key Methods Added/Modified
78+
- **`get_branch_worktree_map()`**: Maps branch names to worktree names, including main worktree detection
79+
- **`list_all_branches()`**: Returns both local and remote branches (remote without "origin/" prefix)
80+
- **`create_worktree_with_new_branch()`**: Creates worktree with new branch from base branch (supports git-flow style workflows)
81+
7082
## Architecture
7183

7284
### Core Module Structure
7385

7486
```
7587
src/
7688
├── main.rs # CLI entry point and main menu loop
89+
├── lib.rs # Library exports
7790
├── commands.rs # Command implementations for menu items
7891
├── git.rs # Git worktree operations (git2 + process::Command)
7992
├── menu.rs # MenuItem enum and icon definitions
@@ -114,12 +127,14 @@ post-switch = ["echo 'Switched to {{worktree_name}}'"]
114127
```
115128

116129
Template variables:
130+
117131
- `{{worktree_name}}`: The worktree name
118132
- `{{worktree_path}}`: Absolute path to worktree
119133

120134
### Worktree Patterns
121135

122136
First worktree creation offers two options:
137+
123138
1. Same level as repository: `../worktree-name`
124139
2. In subdirectory (recommended): `../repo/worktrees/worktree-name`
125140

@@ -128,13 +143,15 @@ Subsequent worktrees follow the established pattern automatically.
128143
### ESC Key Handling
129144

130145
All interactive prompts support ESC cancellation through custom `input_esc_raw` module:
146+
131147
- `input_esc_raw()` returns `Option<String>` (None on ESC)
132148
- `Select::interact_opt()` for menu selections
133149
- `Confirm::interact_opt()` for confirmations
134150

135151
### Worktree Rename Implementation
136152

137153
Since Git lacks native rename functionality:
154+
138155
1. Move directory with `fs::rename`
139156
2. Update `.git/worktrees/<name>` metadata directory
140157
3. Update gitdir files in both directions
@@ -149,9 +166,11 @@ Since Git lacks native rename functionality:
149166

150167
### Testing Considerations
151168

169+
- Integration tests in `tests/` directory (27 test files)
152170
- Some tests are flaky in parallel execution (marked with `#[ignore]`)
153171
- CI sets `CI=true` environment variable to skip flaky tests
154172
- Run with `--test-threads=1` for reliable results
173+
- Use `--nocapture` to see test output for debugging
155174

156175
### Important Constraints
157176

@@ -161,3 +180,4 @@ Since Git lacks native rename functionality:
161180
- Cannot rename worktrees with detached HEAD
162181
- Shell integration supports Bash/Zsh only
163182
- No Windows support (macOS and Linux only)
183+
- Recent breaking change: CLI arguments removed in favor of menu-only interface

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "git-workers"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55
authors = ["Daichi Furiya"]
66
description = "Interactive Git worktree manager with shell integration"
@@ -18,7 +18,7 @@ path = "src/main.rs"
1818
# Git Operations
1919
git2 = { version = "0.20", features = ["vendored-openssl"] }
2020

21-
# CLI Framework
21+
# CLI Framework
2222
dialoguer = "0.11"
2323
console = "0.15"
2424
clap = { version = "4.5", features = ["derive"] }

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ Git Workers provides an interactive menu-driven interface. Simply run `gw` and n
5656

5757
- **List worktrees** (``): Display all worktrees with branch, changes, and sync status
5858
- **Search worktrees** (`?`): Fuzzy search through worktree names and branches
59-
- **Create worktree** (`+`): Create a new worktree from existing branch or create a new branch
59+
- **Create worktree** (`+`): Create a new worktree with two options:
60+
- **Create from current HEAD**: Creates a new worktree with a new branch from the current HEAD
61+
- **Select branch (smart mode)**: Choose from local/remote branches with automatic conflict resolution:
62+
- Shows both local and remote branches with usage status
63+
- Automatically handles branch conflicts (offers to create new branch if already in use)
64+
- Remote branches are prefixed with `` for easy identification
6065
- **Delete worktree** (`-`): Delete a single worktree with safety checks
6166
- **Batch delete** (`=`): Select and delete multiple worktrees at once (optionally deletes orphaned branches)
6267
- **Cleanup old worktrees** (`~`): Remove worktrees older than specified days

0 commit comments

Comments
 (0)