Development Setup
Clone the repository and set up your development environment:cargo fmt --check: Verify code formattingcargo clippy: Run linter checks
Build the Project
Build the project in debug mode:- Debug:
target/debug/gitsw - Release:
target/release/gitsw
Run Tests
Execute the test suite:src/hooks.rs:97- Package manager detection and hashing tests- Unit tests use
tempfilefor isolated filesystem operations
Development Workflow
Making Changes
-
Create a feature branch:
-
Make your changes following the code style:
- Use
cargo fmtto format code - Run
cargo clippyto check for issues - Add tests for new functionality
- Use
-
Test your changes:
-
Commit your changes:
The pre-commit hooks will run automatically. If they fail:
-
Push and create a pull request:
Code Organization
The codebase follows a modular structure defined insrc/lib.rs:1:
Module Responsibilities
main.rs: CLI argument parsing, command routing, high-level workflow orchestration git.rs: All Git operations usinggit2 library (branch, stash, checkout, remote)
hooks.rs: Package manager detection (npm/yarn/pnpm), lock file hashing, install execution
prompt.rs: User interaction via dialoguer (branch picker, confirmations, conflict resolution)
state.rs: JSON state management for stash tracking, lock hashes, and recency data
Adding New Features
Adding a New Command
-
Add CLI argument in
src/main.rs:11to theArgsstruct: -
Add handler in
src/main.rs:67in therun()function: -
Implement handler function in
src/main.rs:
Adding Git Operations
Add new methods to theGitRepo struct in src/git.rs:7:
Adding Package Managers
Extend thePackageManager enum in src/hooks.rs:7:
User Output
Use colored output for user-facing messages:src/hooks.rs:97 for examples.
Integration Testing
For testing with real Git repositories, usetempfile::TempDir: