| 1 |
# Contributing to gitconfig |
| 2 |
|
| 3 |
Thank you for your interest in contributing to gitconfig! This document provides guidelines and instructions for contributing. |
| 4 |
|
| 5 |
## Code of Conduct |
| 6 |
|
| 7 |
Please be respectful and constructive in all interactions within this project. |
| 8 |
|
| 9 |
## Getting Started |
| 10 |
|
| 11 |
### Prerequisites |
| 12 |
|
| 13 |
- Go 1.24 or later |
| 14 |
- Git |
| 15 |
- Make |
| 16 |
|
| 17 |
### Development Setup |
| 18 |
|
| 19 |
1. Clone the repository: |
| 20 |
|
| 21 |
```bash |
| 22 |
git clone https://github.com/gopasspw/gitconfig.git |
| 23 |
cd gitconfig |
| 24 |
``` |
| 25 |
|
| 26 |
1. Install dependencies: |
| 27 |
|
| 28 |
```bash |
| 29 |
go mod tidy |
| 30 |
``` |
| 31 |
|
| 32 |
1. Verify your setup: |
| 33 |
|
| 34 |
```bash |
| 35 |
make test |
| 36 |
make codequality |
| 37 |
``` |
| 38 |
|
| 39 |
All tests should pass and no linting errors should be reported. |
| 40 |
|
| 41 |
## Making Changes |
| 42 |
|
| 43 |
Please see [Development Workflow](DEVELOPMENT.md#development-workflow). |
| 44 |
|
| 45 |
### Testing |
| 46 |
|
| 47 |
#### Running Tests |
| 48 |
|
| 49 |
```bash |
| 50 |
# Run all tests |
| 51 |
make test |
| 52 |
|
| 53 |
# Run specific test |
| 54 |
go test -v -run TestName |
| 55 |
|
| 56 |
# Run with race detection |
| 57 |
go test -race ./... |
| 58 |
``` |
| 59 |
|
| 60 |
#### Writing Tests |
| 61 |
|
| 62 |
1. **Test location:** Add tests to `*_test.go` files next to source code |
| 63 |
2. **Test naming:** Use `TestFunctionName` or `TestFunctionName_Scenario` |
| 64 |
3. **Test structure:** Use table-driven tests where practical |
| 65 |
4. **Parallel tests:** Add `t.Parallel()` to tests that don't rely on shared state |
| 66 |
5. **Assertions:** Use `testify/assert` and `testify/require` |
| 67 |
|
| 68 |
Example test: |
| 69 |
|
| 70 |
```go |
| 71 |
func TestMyFeature(t *testing.T) { |
| 72 |
t.Parallel() |
| 73 |
|
| 74 |
testCases := []struct { |
| 75 |
name string |
| 76 |
input string |
| 77 |
want string |
| 78 |
wantErr bool |
| 79 |
}{ |
| 80 |
{ |
| 81 |
name: "simple case", |
| 82 |
input: "test", |
| 83 |
want: "result", |
| 84 |
wantErr: false, |
| 85 |
}, |
| 86 |
} |
| 87 |
|
| 88 |
for _, tc := range testCases { |
| 89 |
t.Run(tc.name, func(t *testing.T) { |
| 90 |
got, err := MyFunction(tc.input) |
| 91 |
if tc.wantErr { |
| 92 |
assert.Error(t, err) |
| 93 |
} else { |
| 94 |
assert.NoError(t, err) |
| 95 |
assert.Equal(t, tc.want, got) |
| 96 |
} |
| 97 |
}) |
| 98 |
} |
| 99 |
} |
| 100 |
``` |
| 101 |
|
| 102 |
#### Test Coverage |
| 103 |
|
| 104 |
When adding new functionality: |
| 105 |
|
| 106 |
- Aim for >80% code coverage |
| 107 |
- Test both the success path and error cases |
| 108 |
- Include edge case tests |
| 109 |
- Document why certain edge cases are important |
| 110 |
|
| 111 |
### Commit Messages |
| 112 |
|
| 113 |
Use conventional commit format: |
| 114 |
|
| 115 |
```text |
| 116 |
type(scope): short description |
| 117 |
|
| 118 |
Longer explanation if needed. Wrap at 72 characters. |
| 119 |
|
| 120 |
Additional context and motivation. |
| 121 |
|
| 122 |
Fixes #123 |
| 123 |
``` |
| 124 |
|
| 125 |
Common types: |
| 126 |
|
| 127 |
- `feat`: New feature |
| 128 |
- `fix`: Bug fix |
| 129 |
- `docs`: Documentation change |
| 130 |
- `test`: Test addition or modification |
| 131 |
- `refactor`: Code refactoring |
| 132 |
- `perf`: Performance improvement |
| 133 |
- `chore`: Build, dependencies, or tooling |
| 134 |
|
| 135 |
Example: |
| 136 |
|
| 137 |
```text |
| 138 |
feat(parser): add support for bare boolean values |
| 139 |
|
| 140 |
Add parsing support for bare boolean values in gitconfig files |
| 141 |
as per git-config specification. Previously these were silently |
| 142 |
ignored. |
| 143 |
|
| 144 |
Fixes #42 |
| 145 |
``` |
| 146 |
|
| 147 |
## Submitting Changes |
| 148 |
|
| 149 |
### Before Submitting |
| 150 |
|
| 151 |
1. Ensure all tests pass: |
| 152 |
|
| 153 |
```bash |
| 154 |
make test |
| 155 |
``` |
| 156 |
|
| 157 |
2. Run code quality checks: |
| 158 |
|
| 159 |
```bash |
| 160 |
make codequality |
| 161 |
make fmt |
| 162 |
``` |
| 163 |
|
| 164 |
3. Verify cross-compilation works (if changing platform-specific code): |
| 165 |
|
| 166 |
```bash |
| 167 |
make crosscompile |
| 168 |
``` |
| 169 |
|
| 170 |
4. Update documentation if you changed: |
| 171 |
- Public API (update godoc comments) |
| 172 |
- User-facing behavior (update README.md, doc.go) |
| 173 |
- Configuration handling (update CONFIG_FORMAT.md) |
| 174 |
|
| 175 |
### Pull Request Process |
| 176 |
|
| 177 |
1. Push your branch to your fork |
| 178 |
2. Create a pull request with a clear title and description |
| 179 |
3. Link related issues using `Closes #123` or `Fixes #456` |
| 180 |
4. Include any relevant documentation changes |
| 181 |
5. Be ready to respond to code review comments |
| 182 |
|
| 183 |
### What to Include in PR Description |
| 184 |
|
| 185 |
```markdown |
| 186 |
## Description |
| 187 |
Clear description of what changes and why. |
| 188 |
|
| 189 |
## Type of Change |
| 190 |
- [ ] Bug fix (non-breaking) |
| 191 |
- [ ] New feature (non-breaking) |
| 192 |
- [ ] Breaking change |
| 193 |
|
| 194 |
## How to Test |
| 195 |
Steps to verify the changes work. |
| 196 |
|
| 197 |
## Checklist |
| 198 |
- [ ] Tests pass locally |
| 199 |
- [ ] Code formatted with `make fmt` |
| 200 |
- [ ] Linting passes with `make codequality` |
| 201 |
- [ ] Documentation updated |
| 202 |
- [ ] No new dependencies added (or justified) |
| 203 |
``` |
| 204 |
|
| 205 |
## Code Review |
| 206 |
|
| 207 |
Expect constructive feedback on: |
| 208 |
|
| 209 |
- Code clarity and maintainability |
| 210 |
- Test coverage |
| 211 |
- Documentation completeness |
| 212 |
- API design consistency |
| 213 |
- Performance implications |
| 214 |
|
| 215 |
## Common Patterns |
| 216 |
|
| 217 |
### Adding a New Function |
| 218 |
|
| 219 |
1. Implement the function |
| 220 |
2. Add godoc comment with: |
| 221 |
- What it does |
| 222 |
- Parameters and return values |
| 223 |
- Examples |
| 224 |
- Any error conditions |
| 225 |
3. Add tests covering normal and error cases |
| 226 |
4. Run `make fmt` and `make codequality` |
| 227 |
|
| 228 |
### Modifying Existing Functions |
| 229 |
|
| 230 |
1. Check if behavior change is breaking |
| 231 |
2. Update godoc if behavior changed |
| 232 |
3. Add/update tests |
| 233 |
4. Update related documentation |
| 234 |
|
| 235 |
### Adding Dependencies |
| 236 |
|
| 237 |
Before adding a new dependency: |
| 238 |
|
| 239 |
1. Check if stdlib or existing deps can solve the problem |
| 240 |
2. Verify license compatibility (must be MIT or compatible) |
| 241 |
3. Ensure it's pure Go (no CGo) |
| 242 |
4. Document why it's needed in DEPENDENCIES.md |
| 243 |
5. Open an issue to discuss before implementing |
| 244 |
|
| 245 |
## Getting Help |
| 246 |
|
| 247 |
- **Questions:** Open a discussion or issue |
| 248 |
- **Bug reports:** Include reproduction steps, environment, Go version |
| 249 |
- **Feature requests:** Describe the use case and motivation |
| 250 |
- **Design discussions:** Open an issue to discuss before implementing |
| 251 |
|
| 252 |
## Additional Resources |
| 253 |
|
| 254 |
- [git-config documentation](https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-config.html) |
| 255 |
- [ARCHITECTURE.md](./ARCHITECTURE.md) - Design and structure |
| 256 |
- [CONFIG_FORMAT.md](./CONFIG_FORMAT.md) - Supported syntax |
| 257 |
- [DEVELOPMENT.md](./DEVELOPMENT.md) - Deeper technical details |
| 258 |
|
| 259 |
## License |
| 260 |
|
| 261 |
By contributing, you agree that your contributions will be licensed under the MIT License, consistent with the project's license. |
| 262 |
|
| 263 |
## Recognition |
| 264 |
|
| 265 |
Contributors are valued and important to this project. Your contributions help make gitconfig better for everyone. |
| 266 |
|
| 267 |
Thank you for contributing! 🎉 |