{"id":25696629,"url":"https://github.com/tizee/git-hooks","last_synced_at":"2025-09-05T23:42:45.002Z","repository":{"id":274200182,"uuid":"922190662","full_name":"tizee/git-hooks","owner":"tizee","description":"global hooks for git","archived":false,"fork":false,"pushed_at":"2025-02-16T14:05:43.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-16T15:20:05.257Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tizee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-25T15:05:56.000Z","updated_at":"2025-02-16T14:05:47.000Z","dependencies_parsed_at":"2025-01-25T17:18:42.423Z","dependency_job_id":"8bc75124-cd70-42bb-81a2-d5d8a4aac55f","html_url":"https://github.com/tizee/git-hooks","commit_stats":null,"previous_names":["tizee/git-hooks"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tizee%2Fgit-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tizee%2Fgit-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tizee%2Fgit-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tizee%2Fgit-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tizee","download_url":"https://codeload.github.com/tizee/git-hooks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240587491,"owners_count":19825004,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-25T01:54:54.025Z","updated_at":"2025-09-05T23:42:44.984Z","avatar_url":"https://github.com/tizee.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🪝 Advanced Git Hooks Collection\n\nA sophisticated collection of git hooks designed to enhance security, code quality, and developer productivity through automated credential scanning and AI-powered commit message generation.\n\n## 🚀 Features\n\n### 🔐 Security-First Pre-commit Hook\n- **Credential Leak Detection**: Scans for API keys, tokens, passwords, and private keys\n- **Multi-pattern Recognition**: Supports AWS, Google, Stripe, and generic token formats\n- **C/C++ Auto-formatting**: Automatically formats staged C/C++ files using `clang-format`\n- **Bypass Controls**: Environment variable support for temporary disabling\n\n### 🤖 AI-Powered Commit Message Generation\n- **LLM Integration**: Uses `llm` CLI tool for intelligent commit message creation\n- **Smart Caching**: Caches commit messages based on staged changes to avoid regeneration\n- **Cross-platform**: Works on Unix, macOS, and Windows systems\n- **Visual Feedback**: Customizable spinner animations during message generation\n- **Safety Features**: Skip modes for amending commits and merge operations\n\n## 📦 Installation\n\n### Quick Setup (Recommended)\n\n#### Unix/macOS\n```bash\nHOOKS_REPO=\"$HOME/.git-global-hooks\"\ngit clone --depth=1 https://github.com/tizee/git-hooks.git \"$HOOKS_REPO\"\ngit config --global core.hooksPath \"$HOOKS_REPO/hooks\"\n```\n\n#### Windows (PowerShell)\n```powershell\n$HOOKS_REPO = \"$env:USERPROFILE\\.git-global-hooks\"\ngit clone --depth=1 https://github.com/tizee/git-hooks.git \"$HOOKS_REPO\"\ngit config --global core.hooksPath \"$HOOKS_REPO\\hooks\"\n```\n\n### Prerequisites\n\n#### For AI Commit Messages\n- Install the `llm` CLI tool:\n  ```bash\n  pip install llm\n  # or\n  brew install llm  # macOS\n  ```\n- Configure your preferred AI model:\n  ```bash\n  llm keys set openai\n  llm models default gpt-4\n  ```\n\n#### For C/C++ Formatting\n- Install `clang-format`:\n  ```bash\n  # Ubuntu/Debian\n  sudo apt-get install clang-format\n  \n  # macOS\n  brew install clang-format\n  \n  # Windows (via Chocolatey)\n  choco install llvm\n  ```\n\n## ⚙️ Configuration\n\n### Environment Variables\n\n#### Pre-commit Hook\n- `SKIP_SCAN_GITHOOK=1`: Skip security scanning\n- `DISABLE_SECRET_SCAN=1`: Alternative skip flag\n\n#### Prepare-commit-msg Hook\n- `SKIP_LLM_GITHOOK=1`: Skip AI commit message generation entirely\n- `FORCE_LLM_GITHOOK=1`: Force regeneration even with cached/unmodified diffs\n- `NO_BYPASS_AMENDING=1`: Prevent bypass during commit amending (normally bypasses for amends)\n- `GITHOOK_SPINNER=style`: Set custom spinner style (see available styles below)\n- `SPINNER_STYLE=style`: Alternative spinner style variable (fallback to GITHOOK_SPINNER)\n- `LLM_PROGRAM`: Custom path to the `llm` executable (defaults to system `llm`)\n- `LLM_PREPARE_COMMIT_MSG_PROMPT`: Custom path to the prompt template file\n- `PYTHONIOENCODING=utf-8`: Force Python encoding (set automatically for Windows compatibility)\n\n### Available Spinner Styles\n- `classic` (default): `|/-\\`\n- `dots`: `⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏`\n- `arrows`: `←↖↑↗→↘↓↙`\n- `blocks`: `▖▘▝▗`\n- `pulse`: `▁▂▃▄▅▆▇█▇▆▅▄▃▂`\n- `bouncing`: `⠁⠂⠄⡀⢀⠠⠐⠈`\n- `circle`: `◐◓◑◒`\n- `square`: `◰◳◲◱`\n- `triangle`: `◴◵◶◷`\n- `diamond`: `◇◈◆`\n\n### Advanced Environment Variables\n\n#### Custom LLM Configuration\n- **LLM_PROGRAM**: Override the default `llm` command path\n  ```bash\n  export LLM_PROGRAM=\"/usr/local/bin/llm-custom\"\n  export LLM_PREPARE_COMMIT_MSG_PROMPT=\"$HOME/.config/git/commit-prompt.txt\"\n  ```\n\n#### Spinner Customization\n- **GITHOOK_SPINNER**: Primary spinner style selector\n- **SPINNER_STYLE**: Fallback variable if GITHOOK_SPINNER is not set\n  ```bash\n  export GITHOOK_SPINNER=\"dots\"\n  export SPINNER_STYLE=\"arrows\"  # Used if GITHOOK_SPINNER is unset\n  ```\n\n#### Bypass and Control Variables\n- **SKIP_LLM_GITHOOK**: Complete bypass for AI generation\n- **FORCE_LLM_GITHOOK**: Override caching behavior\n- **NO_BYPASS_AMENDING**: Disable automatic bypass during amend operations\n  ```bash\n  # Skip AI for specific repositories\n  export SKIP_LLM_GITHOOK=1\n  \n  # Force regeneration for debugging\n  export FORCE_LLM_GITHOOK=1\n  \n  # Always run AI even when amending\n  export NO_BYPASS_AMENDING=1\n  ```\n\n#### Windows-Specific Variables\n- **PYTHONIOENCODING**: Force UTF-8 encoding (automatically set)\n- **LC_ALL/LANG**: Locale settings for proper encoding\n  ```bash\n  export LC_ALL=en_US.UTF-8\n  export LANG=en_US.UTF-8\n  ```\n\n### Model Name Mapping\nThe system automatically maps common model names for consistency:\n- `doubao-v3` → `deepseek-v3`\n- `doubao-r1` → `deepseek-r1`\n- `siliconflow-r1` → `deepseek-r1`\n- `deepseek-chat` → `deepseek-v3`\n- `deepseek-reasoner` → `deepseek-r1`\n\n## 🔍 Usage Examples\n\n### Basic Usage\n```bash\n# Make changes and commit\ngit add .\ngit commit\n# AI will generate commit message automatically\n```\n\n### Skip Security Scanning\n```bash\n# Skip credential scan for this commit\nSKIP_SCAN_GITHOOK=1 git commit -m \"Quick fix\"\n\n# Set for entire session\nexport SKIP_SCAN_GITHOOK=1\n```\n\n### Skip AI Message Generation\n```bash\n# Use your own commit message\nSKIP_LLM_GITHOOK=1 git commit\n\n# Bypass for amending\ngit commit --amend\n```\n\n### Force Regeneration\n```bash\n# Regenerate even if changes are cached\nFORCE_LLM_GITHOOK=1 git commit --amend\n```\n\n### Custom Spinner Style\n```bash\n# Use dots spinner\nGITHOOK_SPINNER=dots git commit\n\n# Set permanently in your shell profile\necho 'export GITHOOK_SPINNER=dots' \u003e\u003e ~/.zshrc\n```\n\n## 🛠️ Troubleshooting\n\n### Common Issues\n\n#### \"llm command not found\"\n```bash\n# Install llm\npip install llm\n\n# Verify installation\nllm --version\n```\n\n#### \"clang-format not found\"\n```bash\n# Install based on your system\n# Ubuntu/Debian\nsudo apt-get install clang-format\n\n# macOS\nbrew install clang-format\n\n# Verify installation\nclang-format --version\n```\n\n#### Commit stuck on spinner\n- Check network connectivity for AI service\n- Verify AI model configuration: `llm models`\n- Skip AI generation: `SKIP_LLM_GITHOOK=1 git commit`\n\n#### False positive in security scan\n- Review the detected pattern in your code\n- If legitimate, temporarily skip: `SKIP_SCAN_GITHOOK=1 git commit`\n- Consider adjusting the pattern if it's a common false positive\n\n#### Permission issues on Unix systems\n```bash\n# Ensure hooks are executable\nchmod +x ~/.git-global-hooks/hooks/*\n```\n\n### Debug Mode\nEnable verbose output for troubleshooting:\n```bash\n# For pre-commit hook\nbash -x ~/.git-global-hooks/hooks/pre-commit\n\n# For prepare-commit-msg hook\nbash -x ~/.git-global-hooks/hooks/prepare-commit-msg\n```\n\n## 📋 Advanced Configuration\n\n### Custom AI Prompts\nThe prepare-commit-msg hook uses a template system. You can customize the prompt:\n\n```bash\n# View current template\nllm templates show commit-msg\n\n# Create custom template\necho \"Generate a commit message for these changes focusing on: $CHANGES\" | \\\n     llm -s - --save commit-msg-custom\n```\n\n### Cache Management\nCached commit messages are stored in `~/.cache/git-llm-prepare-commit-msg/`:\n- `last_md5`: MD5 hash of staged changes\n- `last_message`: Cached commit message\n\nClear cache:\n```bash\nrm -rf ~/.cache/git-llm-prepare-commit-msg/\n```\n\n### Hook Customization\nTo modify hook behavior, edit the files in `~/.git-global-hooks/hooks/`. Changes take effect immediately.\n\n## 🤝 Contributing\n\nFound a bug or have a feature request? Please open an issue or submit a pull request!\n\n### Development Setup\n```bash\n# Clone for development\ngit clone https://github.com/tizee/git-hooks.git\ncd git-hooks\n\n# Test hooks locally\ngit config core.hooksPath ./hooks\n```\n\n## 📄 License\n\nMIT License - see LICENSE file for details.\n\n## 🙏 Acknowledgments\n\n- [Simon Willison's llm](https://github.com/simonw/llm) for AI integration\n- The git community for hook system inspiration\n- Contributors and users who provide feedback and improvements","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftizee%2Fgit-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftizee%2Fgit-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftizee%2Fgit-hooks/lists"}