|
| 1 | +# Contributing to gtr |
| 2 | + |
| 3 | +Thank you for considering contributing to `gtr`! This document provides guidelines and instructions for contributing. |
| 4 | + |
| 5 | +## How to Contribute |
| 6 | + |
| 7 | +### Reporting Issues |
| 8 | + |
| 9 | +Before creating an issue, please: |
| 10 | + |
| 11 | +1. **Search existing issues** to avoid duplicates |
| 12 | +2. **Provide a clear description** of the problem |
| 13 | +3. **Include your environment details**: |
| 14 | + - OS and version (macOS, Linux distro, Windows Git Bash) |
| 15 | + - Git version |
| 16 | + - Shell (bash, zsh, fish) |
| 17 | +4. **Steps to reproduce** the issue |
| 18 | +5. **Expected vs actual behavior** |
| 19 | + |
| 20 | +### Suggesting Features |
| 21 | + |
| 22 | +We welcome feature suggestions! Please: |
| 23 | + |
| 24 | +1. **Check existing issues** for similar requests |
| 25 | +2. **Describe the use case** - why is this needed? |
| 26 | +3. **Propose a solution** if you have one in mind |
| 27 | +4. **Consider backwards compatibility** and cross-platform support |
| 28 | + |
| 29 | +## Development |
| 30 | + |
| 31 | +### Architecture Overview |
| 32 | + |
| 33 | +``` |
| 34 | +git-worktree-runner/ |
| 35 | +├── bin/gtr # Main executable dispatcher |
| 36 | +├── lib/ # Core functionality |
| 37 | +│ ├── core.sh # Git worktree operations |
| 38 | +│ ├── config.sh # Configuration (git-config wrapper) |
| 39 | +│ ├── platform.sh # OS-specific utilities |
| 40 | +│ ├── ui.sh # User interface (logging, prompts) |
| 41 | +│ ├── copy.sh # File copying logic |
| 42 | +│ └── hooks.sh # Hook execution |
| 43 | +├── adapters/ # Pluggable integrations |
| 44 | +│ ├── editor/ # Editor adapters (cursor, vscode, zed) |
| 45 | +│ └── ai/ # AI tool adapters (aider) |
| 46 | +├── completions/ # Shell completions (bash, zsh, fish) |
| 47 | +└── templates/ # Example configs and scripts |
| 48 | +``` |
| 49 | + |
| 50 | +### Coding Standards |
| 51 | + |
| 52 | +#### Shell Script Best Practices |
| 53 | + |
| 54 | +- **Bash requirement**: All scripts use Bash (use `#!/usr/bin/env bash`) |
| 55 | +- **Set strict mode**: Use `set -e` to exit on errors |
| 56 | +- **Quote variables**: Always quote variables: `"$var"` |
| 57 | +- **Use local variables**: Declare function-local vars with `local` |
| 58 | +- **Error handling**: Check return codes and provide clear error messages |
| 59 | +- **Target Bash 3.2+**: Code runs on Bash 3.2+ (macOS default), but Bash 4.0+ features (like globstar) are allowed where appropriate |
| 60 | + |
| 61 | +#### Code Style |
| 62 | + |
| 63 | +- **Function names**: Use `snake_case` for functions |
| 64 | +- **Variable names**: Use `snake_case` for variables |
| 65 | +- **Constants**: Use `UPPER_CASE` for constants/env vars |
| 66 | +- **Indentation**: 2 spaces (no tabs) |
| 67 | +- **Line length**: Keep lines under 100 characters when possible |
| 68 | +- **Comments**: Add comments for complex logic |
| 69 | + |
| 70 | +#### Example: |
| 71 | + |
| 72 | +```bash |
| 73 | +#!/usr/bin/env bash |
| 74 | +# Brief description of what this file does |
| 75 | + |
| 76 | +# Function description |
| 77 | +do_something() { |
| 78 | + local input="$1" |
| 79 | + local result |
| 80 | + |
| 81 | + if [ -z "$input" ]; then |
| 82 | + log_error "Input required" |
| 83 | + return 1 |
| 84 | + fi |
| 85 | + |
| 86 | + result=$(some_command "$input") |
| 87 | + printf "%s" "$result" |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +### Adding New Features |
| 92 | + |
| 93 | +#### Adding an Editor Adapter |
| 94 | + |
| 95 | +1. Create `adapters/editor/yourname.sh`: |
| 96 | + |
| 97 | +```bash |
| 98 | +#!/usr/bin/env bash |
| 99 | +# YourEditor adapter |
| 100 | + |
| 101 | +editor_can_open() { |
| 102 | + command -v yourcommand >/dev/null 2>&1 |
| 103 | +} |
| 104 | + |
| 105 | +editor_open() { |
| 106 | + local path="$1" |
| 107 | + |
| 108 | + if ! editor_can_open; then |
| 109 | + log_error "YourEditor not found. Install from https://..." |
| 110 | + return 1 |
| 111 | + fi |
| 112 | + |
| 113 | + yourcommand "$path" |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +2. Update README.md with setup instructions |
| 118 | +3. Update completions to include new editor |
| 119 | +4. Test on macOS, Linux, and Windows if possible |
| 120 | + |
| 121 | +#### Adding an AI Tool Adapter |
| 122 | + |
| 123 | +1. Create `adapters/ai/yourtool.sh`: |
| 124 | + |
| 125 | +```bash |
| 126 | +#!/usr/bin/env bash |
| 127 | +# YourTool AI adapter |
| 128 | + |
| 129 | +ai_can_start() { |
| 130 | + command -v yourtool >/dev/null 2>&1 |
| 131 | +} |
| 132 | + |
| 133 | +ai_start() { |
| 134 | + local path="$1" |
| 135 | + shift |
| 136 | + |
| 137 | + if ! ai_can_start; then |
| 138 | + log_error "YourTool not found. Install with: ..." |
| 139 | + return 1 |
| 140 | + fi |
| 141 | + |
| 142 | + (cd "$path" && yourtool "$@") |
| 143 | +} |
| 144 | +``` |
| 145 | + |
| 146 | +2. Update README.md |
| 147 | +3. Update completions |
| 148 | +4. Add example usage |
| 149 | + |
| 150 | +#### Adding Core Features |
| 151 | + |
| 152 | +For changes to core functionality (`lib/*.sh`): |
| 153 | + |
| 154 | +1. **Discuss first**: Open an issue to discuss the change |
| 155 | +2. **Maintain compatibility**: Avoid breaking existing configs |
| 156 | +3. **Add tests**: Provide test cases or manual testing instructions |
| 157 | +4. **Update docs**: Update README.md and help text |
| 158 | +5. **Consider edge cases**: Think about error conditions |
| 159 | + |
| 160 | +### Testing |
| 161 | + |
| 162 | +Currently, testing is manual. Please test your changes on: |
| 163 | + |
| 164 | +1. **macOS** (if available) |
| 165 | +2. **Linux** (Ubuntu, Fedora, or Arch recommended) |
| 166 | +3. **Windows Git Bash** (if available) |
| 167 | + |
| 168 | +#### Manual Testing Checklist |
| 169 | + |
| 170 | +- [ ] Create worktree with branch name |
| 171 | +- [ ] Create worktree with branch containing slashes (e.g., feature/auth) |
| 172 | +- [ ] Create from remote branch |
| 173 | +- [ ] Create from local branch |
| 174 | +- [ ] Create new branch |
| 175 | +- [ ] Open in editor (if testing adapters) |
| 176 | +- [ ] Run AI tool (if testing adapters) |
| 177 | +- [ ] Remove worktree by branch name |
| 178 | +- [ ] List worktrees |
| 179 | +- [ ] Test configuration commands |
| 180 | +- [ ] Test completions (tab completion works) |
| 181 | +- [ ] Test `gtr go 1` for main repo |
| 182 | +- [ ] Test `gtr go <branch>` for worktrees |
| 183 | + |
| 184 | +### Pull Request Process |
| 185 | + |
| 186 | +1. **Fork the repository** |
| 187 | +2. **Create a feature branch**: `git checkout -b feature/my-feature` |
| 188 | +3. **Make your changes** |
| 189 | +4. **Test thoroughly** (see checklist above) |
| 190 | +5. **Update documentation** (README.md, help text, etc.) |
| 191 | +6. **Commit with clear messages**: |
| 192 | + - Use present tense: "Add feature" not "Added feature" |
| 193 | + - Be descriptive: "Add VS Code adapter" not "Add adapter" |
| 194 | +7. **Push to your fork** |
| 195 | +8. **Open a Pull Request** with: |
| 196 | + - Clear description of changes |
| 197 | + - Link to related issues |
| 198 | + - Testing performed |
| 199 | + - Screenshots/examples if applicable |
| 200 | + |
| 201 | +### Commit Message Format |
| 202 | + |
| 203 | +``` |
| 204 | +<type>: <short description> |
| 205 | +
|
| 206 | +<optional longer description> |
| 207 | +
|
| 208 | +<optional footer> |
| 209 | +``` |
| 210 | + |
| 211 | +**Types:** |
| 212 | + |
| 213 | +- `feat`: New feature |
| 214 | +- `fix`: Bug fix |
| 215 | +- `docs`: Documentation changes |
| 216 | +- `refactor`: Code refactoring (no functional changes) |
| 217 | +- `test`: Adding or updating tests |
| 218 | +- `chore`: Maintenance tasks |
| 219 | + |
| 220 | +**Examples:** |
| 221 | + |
| 222 | +``` |
| 223 | +feat: add JetBrains IDE adapter |
| 224 | +
|
| 225 | +Add support for opening worktrees in IntelliJ, PyCharm, and other |
| 226 | +JetBrains IDEs via the 'idea' command. |
| 227 | +
|
| 228 | +Closes #42 |
| 229 | +``` |
| 230 | + |
| 231 | +``` |
| 232 | +fix: handle spaces in worktree paths |
| 233 | +
|
| 234 | +Properly quote paths in all commands to support directories with spaces. |
| 235 | +``` |
| 236 | + |
| 237 | +## Design Principles |
| 238 | + |
| 239 | +When contributing, please keep these principles in mind: |
| 240 | + |
| 241 | +1. **Cross-platform first** - Code should work on macOS, Linux, and Windows |
| 242 | +2. **No external dependencies** - Avoid requiring tools beyond git and basic shell |
| 243 | +3. **Config over code** - Prefer configuration over hardcoding behavior |
| 244 | +4. **Fail safely** - Validate inputs and provide clear error messages |
| 245 | +5. **Stay modular** - Keep functions small and focused |
| 246 | +6. **User-friendly** - Prioritize good UX and clear documentation |
| 247 | + |
| 248 | +## Community |
| 249 | + |
| 250 | +- **Be respectful** and constructive |
| 251 | +- **Help others** who are learning |
| 252 | +- **Share knowledge** and best practices |
| 253 | +- **Have fun!** This is a community project |
| 254 | + |
| 255 | +## Questions? |
| 256 | + |
| 257 | +- Open an issue for questions |
| 258 | +- Check existing issues and docs first |
| 259 | +- Be patient - maintainers are volunteers |
| 260 | + |
| 261 | +Thank you for contributing! 🎉 |
0 commit comments