@@ -35,6 +35,10 @@ cargo test -- --test-threads=1
3535
3636# Run tests with output for debugging
3737cargo test test_name -- --nocapture
38+
39+ # Run with logging enabled
40+ RUST_LOG=debug cargo run
41+ RUST_LOG=git_workers=trace cargo run
3842```
3943
4044### Quality Checks
@@ -52,6 +56,12 @@ cargo check --all-features
5256
5357# Generate documentation
5458cargo doc --no-deps --open
59+
60+ # Run all checks (using bun if available)
61+ bun run check
62+
63+ # Coverage report (requires cargo-llvm-cov)
64+ cargo llvm-cov --html --lib --ignore-filename-regex ' (tests/|src/main\.rs|src/bin/)' --open
5565```
5666
5767### Installation
@@ -112,17 +122,26 @@ source /path/to/git-workers/shell/gw.sh
112122```
113123src/
114124├── main.rs # CLI entry point and main menu loop
115- ├── lib.rs # Library exports
125+ ├── lib.rs # Library exports and module re-exports
116126├── commands.rs # Command implementations for menu items
117- ├── git.rs # Git worktree operations (git2 + process::Command)
118127├── menu.rs # MenuItem enum and icon definitions
119128├── config.rs # .git-workers.toml configuration management
120- ├── hooks.rs # Hook system (post-create, pre-remove, etc.)
121129├── repository_info.rs # Repository information display
122130├── input_esc_raw.rs # Custom input handling with ESC support
123131├── constants.rs # Centralized constants (strings, formatting)
124- ├── file_copy.rs # File copy functionality for gitignored files
125- └── utils.rs # Common utilities (error display, etc.)
132+ ├── utils.rs # Common utilities (error display, etc.)
133+ ├── ui.rs # User interface abstraction layer
134+ ├── git_interface.rs # Git operations trait abstraction
135+ ├── core/ # Core business logic (UI/infra independent)
136+ │ ├── mod.rs # Module exports
137+ │ ├── models.rs # Core data models (Worktree, Branch, etc.)
138+ │ └── validation.rs # Validation logic for names and paths
139+ └── infrastructure/ # Infrastructure implementations
140+ ├── mod.rs # Module exports
141+ ├── git.rs # Git worktree operations (git2 + process::Command)
142+ ├── hooks.rs # Hook system (post-create, pre-remove, etc.)
143+ ├── file_copy.rs # File copy functionality for gitignored files
144+ └── filesystem.rs # Filesystem operations and utilities
126145```
127146
128147### Technology Stack
@@ -193,15 +212,18 @@ Since Git lacks native rename functionality:
193212
194213### Testing Considerations
195214
196- - Integration tests in ` tests/ ` directory (30 test files)
215+ - Integration tests in ` tests/ ` directory (17 test files after consolidation )
197216- Some tests are flaky in parallel execution (marked with ` #[ignore] ` )
198217- CI sets ` CI=true ` environment variable to skip flaky tests
199218- Run with ` --test-threads=1 ` for reliable results
200219- Use ` --nocapture ` to see test output for debugging
201- - New test files added:
202- - ` worktree_path_test.rs ` : Tests for path resolution and edge cases
203- - ` create_worktree_integration_test.rs ` : Integration tests for worktree creation
204- - ` create_worktree_from_tag_test.rs ` : Tests for tag listing and worktree creation from tags
220+
221+ ### Common Error Patterns and Solutions
222+
223+ 1 . ** "Permission denied" when running tests** : Tests create temporary directories; ensure proper permissions
224+ 2 . ** "Repository not found" errors** : Tests require git to be configured (` git config --global user.name/email ` )
225+ 3 . ** Flaky test failures** : Use ` --test-threads=1 ` to avoid race conditions in worktree operations
226+ 4 . ** "Lock file exists" errors** : Clean up ` .git/git-workers-worktree.lock ` if tests are interrupted
205227
206228### String Formatting
207229
@@ -411,3 +433,40 @@ The following test files were consolidated into unified versions:
411433- Individual component tests → `unified_*_comprehensive_test.rs`
412434- Duplicate functionality tests → Removed
413435- Japanese comments → Translated to English
436+
437+ # # Key Implementation Patterns
438+
439+ # ## Git Operations
440+
441+ The codebase uses two approaches for Git operations :
442+
443+ 1. **git2 library** : For read operations (listing branches, getting commit info)
444+ 2. **std::process::Command** : For write operations (worktree add/remove) to ensure compatibility
445+
446+ Example pattern :
447+
448+ ` ` ` rust
449+ // Read operation using git2
450+ let repo = Repository::open(".")?;
451+ let branches = repo.branches(Some(BranchType::Local))?;
452+
453+ // Write operation using Command
454+ Command::new("git")
455+ .args(&["worktree", "add", path, branch])
456+ .output()?;
457+ ` ` `
458+
459+ # ## Error Handling Philosophy
460+
461+ - Use `anyhow::Result` for application-level errors
462+ - Provide context with `.context()` for better error messages
463+ - Show user-friendly messages via `utils::display_error()`
464+ - Never panic in production code; handle all error cases gracefully
465+
466+ # ## UI Abstraction
467+
468+ The `ui::UserInterface` trait enables testing of interactive features :
469+
470+ - Mock implementations for tests
471+ - Real implementation wraps dialoguer
472+ - All user interactions go through this abstraction
0 commit comments