|
| 1 | +# Smart Git Commit 🚀 |
| 2 | + |
| 3 | +An AI-powered Git workflow tool that intelligently analyzes your changes, groups them into logical commits, and generates detailed conventional commit messages. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- 🤖 **AI-Powered Analysis**: Leverages Ollama models to understand your code changes |
| 8 | +- 🔍 **Intelligent Grouping**: Organizes changes into logical, atomic commits |
| 9 | +- 📝 **Conventional Commits**: Generates structured commit messages following the convention |
| 10 | +- 🔄 **Tech Stack Detection**: Automatically adapts to different programming languages and frameworks |
| 11 | +- 🚀 **GPU Acceleration**: Uses hardware acceleration for faster processing |
| 12 | +- ⚡ **Fallback Mechanism**: Works even without AI using rule-based analysis |
| 13 | +- 🎯 **Smart Change Importance**: Prioritizes changes based on impact analysis |
| 14 | +- 🧩 **Component Detection**: Identifies file components based on project structure |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +```bash |
| 19 | +# Install from PyPI |
| 20 | +pip install smart-git-commit |
| 21 | + |
| 22 | +# Or install directly from the repository |
| 23 | +pip install git+https://github.com/yourusername/smart-git-commit.git |
| 24 | +``` |
| 25 | + |
| 26 | +## Requirements |
| 27 | + |
| 28 | +- Python 3.7+ |
| 29 | +- Git |
| 30 | +- Ollama (optional, for AI-powered features) |
| 31 | + |
| 32 | +## Usage |
| 33 | + |
| 34 | +```bash |
| 35 | +# Basic usage (will prompt for Ollama model selection) |
| 36 | +smart-git-commit |
| 37 | + |
| 38 | +# Disable AI-powered analysis |
| 39 | +smart-git-commit --no-ai |
| 40 | + |
| 41 | +# Use a specific Ollama model |
| 42 | +smart-git-commit --ollama-model llama3 |
| 43 | + |
| 44 | +# Non-interactive mode |
| 45 | +smart-git-commit --non-interactive |
| 46 | + |
| 47 | +# Specify a repository path |
| 48 | +smart-git-commit --repo-path /path/to/your/repository |
| 49 | + |
| 50 | +# See all options |
| 51 | +smart-git-commit --help |
| 52 | +``` |
| 53 | + |
| 54 | +### Command Line Options |
| 55 | + |
| 56 | +``` |
| 57 | +usage: smart-git-commit [-h] [--repo-path REPO_PATH] [--non-interactive] |
| 58 | + [--ollama-host OLLAMA_HOST] |
| 59 | + [--ollama-model OLLAMA_MODEL] [--no-ai] |
| 60 | +
|
| 61 | +Smart Git Commit Workflow with Ollama Integration |
| 62 | +
|
| 63 | +options: |
| 64 | + -h, --help show this help message and exit |
| 65 | + --repo-path REPO_PATH |
| 66 | + Path to the git repository |
| 67 | + --non-interactive Run without interactive prompts |
| 68 | + --ollama-host OLLAMA_HOST |
| 69 | + Host for Ollama API |
| 70 | + --ollama-model OLLAMA_MODEL |
| 71 | + Model to use for Ollama (will prompt if not specified) |
| 72 | + --no-ai Disable AI-powered analysis |
| 73 | +``` |
| 74 | + |
| 75 | +## Example Commit |
| 76 | + |
| 77 | +Here's an example of a commit message generated by Smart Git Commit: |
| 78 | + |
| 79 | +``` |
| 80 | +feat(api-auth): Add JWT token validation middleware |
| 81 | +
|
| 82 | +Implement secure JWT token validation with proper error handling and |
| 83 | +expiration checks. Add support for refresh tokens with configurable |
| 84 | +lifetime settings. |
| 85 | +
|
| 86 | +Affected files: |
| 87 | +- M src/auth/jwt_validator.js |
| 88 | +- M src/middleware/auth.js |
| 89 | +- + src/utils/token_helpers.js |
| 90 | +- M config/auth.json |
| 91 | +
|
| 92 | +Fixes #123 |
| 93 | +``` |
| 94 | + |
| 95 | +## How It Works |
| 96 | + |
| 97 | +### Workflow Overview |
| 98 | + |
| 99 | +1. **Load Changes**: Detects all modified and untracked files in the Git repository |
| 100 | +2. **Analyze Changes**: Examines each file's content, language, and importance |
| 101 | +3. **Group Changes**: Organizes related files into logical, atomic commits |
| 102 | +4. **Generate Commit Messages**: Creates detailed, conventional commit messages |
| 103 | +5. **Execute Commits**: Handles the git staging and commit process |
| 104 | + |
| 105 | +### Change Analysis |
| 106 | + |
| 107 | +The tool analyzes changes through multiple dimensions: |
| 108 | + |
| 109 | +- **File Status**: Checks if files are modified, added, or deleted |
| 110 | +- **Language Detection**: Identifies programming languages based on file extensions |
| 111 | +- **Component Recognition**: Maps files to logical components (e.g., docs, tests, api) |
| 112 | +- **Tech Stack Detection**: Detects project technologies (e.g., Python, Node.js, React) |
| 113 | +- **Importance Rating**: With AI, assesses the impact and significance of each change |
| 114 | + |
| 115 | +### Intelligent Grouping |
| 116 | + |
| 117 | +Changes are grouped based on: |
| 118 | + |
| 119 | +- **Component Coherence**: Files from the same component are grouped together |
| 120 | +- **Logical Relationship**: AI analyzes file dependencies and relationships |
| 121 | +- **Change Size Management**: Large groups are split into smaller, coherent commits |
| 122 | +- **Commit Type Assignment**: Each group is assigned a conventional commit type (feat, fix, etc.) |
| 123 | + |
| 124 | +### Ollama LLM Integration |
| 125 | + |
| 126 | +When using AI mode (default): |
| 127 | + |
| 128 | +1. Smart Git Commit connects to Ollama's API |
| 129 | +2. Available LLM models are detected automatically |
| 130 | +3. The selected model analyzes file changes and content |
| 131 | +4. AI determines logical groupings and generates commit descriptions |
| 132 | +5. GPU acceleration is used when available |
| 133 | + |
| 134 | +### Non-AI Fallback |
| 135 | + |
| 136 | +When AI is unavailable or disabled: |
| 137 | + |
| 138 | +1. Files are grouped by component/directory |
| 139 | +2. Commit types are assigned based on file paths and extensions |
| 140 | +3. Basic commit messages are generated using rule-based templates |
| 141 | +4. The user can interactively refine the commit details |
| 142 | + |
| 143 | +### Interactive Workflow |
| 144 | + |
| 145 | +In interactive mode (default): |
| 146 | + |
| 147 | +1. Each commit group is presented for review |
| 148 | +2. You can approve, skip, or edit the commit details |
| 149 | +3. Edit options include changing the commit name, type, description, and issue references |
| 150 | +4. The tool handles staging and committing the files |
| 151 | +5. You can review the final commit before proceeding to the next group |
| 152 | + |
| 153 | +## Project Structure |
| 154 | + |
| 155 | +- **`CommitType` Enum**: Defines conventional commit types (feat, fix, docs, etc.) |
| 156 | +- **`GitChange` Class**: Represents a changed file with metadata |
| 157 | +- **`CommitGroup` Class**: Groups related changes for a single commit |
| 158 | +- **`OllamaClient` Class**: Handles communication with Ollama API |
| 159 | +- **`SmartGitCommitWorkflow` Class**: Orchestrates the entire commit process |
| 160 | + |
| 161 | +## Advanced Usage |
| 162 | + |
| 163 | +### Using Custom Ollama Endpoints |
| 164 | + |
| 165 | +```bash |
| 166 | +# Use a different Ollama host |
| 167 | +smart-git-commit --ollama-host http://custom-ollama-server:11434 |
| 168 | +``` |
| 169 | + |
| 170 | +### Non-Interactive Automation |
| 171 | + |
| 172 | +```bash |
| 173 | +# For CI/CD or automated scripts |
| 174 | +smart-git-commit --non-interactive |
| 175 | +``` |
| 176 | + |
| 177 | +### Working with Multiple Repositories |
| 178 | + |
| 179 | +```bash |
| 180 | +# Specify the repository path |
| 181 | +smart-git-commit --repo-path /path/to/your/repository |
| 182 | +``` |
| 183 | + |
| 184 | +## Troubleshooting |
| 185 | + |
| 186 | +### Ollama Connection Issues |
| 187 | + |
| 188 | +If you encounter issues connecting to Ollama: |
| 189 | + |
| 190 | +1. Ensure Ollama is running: `ollama serve` |
| 191 | +2. Check that you have at least one model: `ollama list` |
| 192 | +3. Try specifying the host explicitly: `--ollama-host http://localhost:11434` |
| 193 | + |
| 194 | +### Falling Back to Non-AI Mode |
| 195 | + |
| 196 | +If AI analysis isn't working properly: |
| 197 | + |
| 198 | +```bash |
| 199 | +# Run with fallback mode explicitly |
| 200 | +smart-git-commit --no-ai |
| 201 | +``` |
| 202 | + |
| 203 | +## Contributing |
| 204 | + |
| 205 | +Contributions are welcome! Please feel free to submit a Pull Request. |
| 206 | + |
| 207 | +To set up your development environment: |
| 208 | + |
| 209 | +1. Clone the repository |
| 210 | +2. Install development dependencies: `pip install -e ".[dev]"` |
| 211 | +3. Run tests: `pytest tests/` |
| 212 | + |
| 213 | +## License |
| 214 | + |
| 215 | +MIT |
| 216 | + |
| 217 | +## Acknowledgements |
| 218 | + |
| 219 | +- [Conventional Commits](https://www.conventionalcommits.org/) for the commit message format |
| 220 | +- [Ollama](https://github.com/ollama/ollama) for the local LLM capabilities |
0 commit comments