An open API service indexing awesome lists of open source software.

https://github.com/knsh14/gitcc


https://github.com/knsh14/gitcc

Last synced: 8 months ago
JSON representation

Awesome Lists containing this project

README

          

# gitcc - Git Configuration Checker

[![Go Version](https://img.shields.io/badge/go-1.19+-blue.svg)](https://golang.org)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)

A command-line tool that helps manage git user configuration across different repositories. gitcc automatically checks if your current repository has appropriate user settings and allows you to select from a predefined list of users when needed.

## Features

- 🔍 **Automatic Detection**: Checks if local git user configuration exists in repository
- 👥 **User Management**: Maintains a list of users in a TOML configuration file
- 🎯 **Smart Selection**: Only prompts for user selection when needed
- 🤫 **Quiet Mode**: Supports quiet operation for scripting scenarios
- ✅ **Exit Codes**: Returns meaningful exit codes for different error conditions
- 🏗️ **Clean Architecture**: Well-structured codebase with comprehensive tests

## How It Works

gitcc follows a simple workflow:

1. **Check Local Configuration**: Verifies if the current repository has local git user settings
2. **Validate User**: Checks if the current user exists in your configured user list
3. **Interactive Selection**: If needed, presents a menu to choose from available users
4. **Apply Configuration**: Sets the selected user for the current repository

## Installation

### From Source

```bash
# Clone the repository
git clone https://github.com/knsh14/gitcc.git
cd gitcc

# Build the binary
go build -o gitcc ./cmd/gitcc

# Install to your PATH (optional)
sudo mv gitcc /usr/local/bin/
```

### Using Go Install

```bash
go install github.com/knsh14/gitcc/cmd/gitcc@latest
```

## Configuration

Create a configuration file at `~/.gitcc.toml` with your available users:

```toml
[[users]]
name = "John Doe"
email = "john.doe@work.com"

[[users]]
name = "John Doe"
email = "john.doe@personal.com"

[[users]]
name = "Jane Smith"
email = "jane@company.com"

[[users]]
name = "Developer"
email = "dev@localhost"
```

## Usage

### Basic Usage

```bash
# Run in any git repository
gitcc
```

### Command Line Options

```bash
# Suppress error messages (useful for scripting)
gitcc -quiet
gitcc -q

# Show help
gitcc -h
gitcc --help
```

### Example Output

```bash
$ gitcc
Current Git Configuration:
user.name: John Doe
user.email: john.doe@oldcompany.com

Current user is not in the configured user list.

Available users:
1. John Doe
2. John Doe
3. Jane Smith
4. Developer

Select a user (1-4): 1

Git configuration updated:
user.name: John Doe
user.email: john.doe@work.com
```

## Exit Codes

gitcc returns different exit codes based on the type of error encountered:

- **0**: Success (no error)
- **1**: General error
- **2**: Configuration error (missing or invalid config file, no users configured)
- **3**: Git error (git not installed, not in repository, git command failed)
- **4**: User input error (invalid selection, out of range, no input provided)
- **5**: Validation error (empty name/email, invalid email format)

This makes gitcc suitable for use in scripts:

```bash
# Check if gitcc succeeded
if gitcc -q; then
echo "Git configuration is properly set"
else
echo "Failed to configure git user (exit code: $?)"
fi
```

## Use Cases

### Work vs Personal Repositories

Keep separate identities for work and personal projects:

```toml
[[users]]
name = "John Doe"
email = "john.doe@company.com"

[[users]]
name = "John Doe"
email = "john@personal.email.com"
```

### Team Development

Share a common configuration across team members:

```toml
[[users]]
name = "Alice Johnson"
email = "alice@company.com"

[[users]]
name = "Bob Smith"
email = "bob@company.com"

[[users]]
name = "Service Account"
email = "ci@company.com"
```

### Development Environments

Use different identities for different environments:

```toml
[[users]]
name = "Developer"
email = "dev@localhost"

[[users]]
name = "Test User"
email = "test@staging.com"

[[users]]
name = "Production User"
email = "prod@company.com"
```

## Development

### Prerequisites

- Go 1.19 or later
- Git

### Building from Source

```bash
# Clone the repository
git clone https://github.com/knsh14/gitcc.git
cd gitcc

# Install dependencies
go mod tidy

# Run tests
go test ./...

# Build the application
go build -o gitcc ./cmd/gitcc

# Run the application
./gitcc
```

### Project Structure

```
gitcc/
├── cmd/
│ └── gitcc/
│ └── main.go # CLI entry point and flag parsing
├── internal/
│ ├── app/ # Application logic and orchestration
│ │ ├── app.go
│ │ └── app_test.go
│ ├── config/ # Configuration file handling
│ │ ├── config.go
│ │ └── config_test.go
│ ├── errors/ # Centralized error definitions
│ │ ├── errors.go
│ │ └── errors_test.go
│ ├── git/ # Git operations
│ │ └── git.go
│ └── ui/ # User interface operations
│ ├── ui.go
│ └── ui_test.go
├── testdata/ # Test data files
│ ├── valid_users.toml
│ ├── invalid_toml.toml
│ └── ...
├── go.mod
├── go.sum
├── README.md
└── CLAUDE.md # Development guidance
```

### Architecture

The project follows clean architecture principles:

- **`cmd/gitcc`**: Entry point with CLI argument parsing
- **`internal/app`**: Core application logic and orchestration
- **`internal/config`**: TOML configuration file handling
- **`internal/git`**: Git command operations
- **`internal/ui`**: User interface and input/output
- **`internal/errors`**: Centralized error definitions using sentinel errors

### Testing

```bash
# Run all tests
go test ./...

# Run tests with coverage
go test -v -cover ./...

# Run tests for a specific package
go test ./internal/config

# Run a specific test
go test -run TestLoadAvailableUsers ./internal/config
```

### Error Handling

The project uses Go's standard error handling patterns:

- **Sentinel errors**: Defined using `errors.New()` for consistent error checking
- **Error wrapping**: Uses `fmt.Errorf` with `%w` verb to maintain error chains
- **Error checking**: Uses `errors.Is()` for proper error type assertion

## Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Make your changes
4. Add tests for new functionality
5. Ensure all tests pass (`go test ./...`)
6. Format your code (`go fmt ./...`)
7. Commit your changes (`git commit -m 'Add amazing feature'`)
8. Push to the branch (`git push origin feature/amazing-feature`)
9. Open a Pull Request

### Code Style

- Follow standard Go conventions
- Use `gofmt` for formatting
- Write clear, descriptive commit messages
- Add tests for new functionality
- Update documentation as needed

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Acknowledgments

- Built with Go's standard library
- Uses [BurntSushi/toml](https://github.com/BurntSushi/toml) for TOML parsing
- Inspired by the need for better git user management across multiple repositories