Metadata-Version: 2.4
Name: bugyo-git
Version: 1.0.1
Summary: Git repository plugin for Daimyo - provides Git context for templates
Project-URL: Homepage, https://gitlab.com/Kencho1/daimyo
Project-URL: Documentation, https://gitlab.com/Kencho1/daimyo/-/blob/main/plugins/bugyo-git/README.md
Project-URL: Repository, https://gitlab.com/Kencho1/daimyo
Project-URL: Issues, https://gitlab.com/Kencho1/daimyo/-/issues
Author: Jesús Alonso Abad
License: MIT License
        
        Copyright (c) 2025 Jesús Alonso Abad
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: daimyo,git,jinja2,plugin,templates
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Version Control :: Git
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: daimyo>=1.4.0
Requires-Dist: gitpython~=3.1
Description-Content-Type: text/markdown

# bugyo-git

Git repository plugin for Daimyo - provides Git context, filters, and tests for Jinja2 templates.

## Installation

```bash
pip install bugyo-git
```

## Requirements

- Python >= 3.11
- daimyo >= 1.4.0
- GitPython ~= 3.1

**Note**: This plugin requires GitPython and only works inside Git repositories.

## Features

### Context Variables

The `git.context` plugin provides:

| Variable | Type | Description |
|----------|------|-------------|
| `git_branch` | str | Current branch name |
| `git_commit` | str | Current commit SHA (short, 7 chars) |
| `git_commit_full` | str | Full commit SHA (40 chars) |
| `git_author` | str | Commit author name |
| `git_author_email` | str | Commit author email |
| `git_remote` | str\|None | Remote URL (if configured) |
| `git_remote_name` | str\|None | Remote name (e.g., "origin") |
| `git_is_clean` | bool | True if no uncommitted changes |
| `git_tag` | str\|None | Tag name if current commit is tagged |
| `git_root` | str | Git repository root path |

### Filters

The `git.filters` plugin provides:

| Filter | Description | Example |
|--------|-------------|---------|
| `git_short_sha` | Shorten SHA to N chars | `commit \| git_short_sha(10)` |
| `git_branch_name` | Extract branch from ref | `"refs/heads/main" \| git_branch_name` |

### Tests

The `git.filters` plugin provides:

| Test | Description | Example |
|------|-------------|---------|
| `is_git_repo` | Check if path is git repo | `"." is is_git_repo` |
| `is_clean` | Check if working dir is clean | `git_is_clean is is_clean` |
| `has_uncommitted` | Check for uncommitted changes | `true is has_uncommitted` |
| `on_branch` | Check if on specific branch | `"main" is on_branch("main")` |
| `has_remote` | Check if remote exists | `"origin" is has_remote("origin")` |

## Configuration

Enable in `.daimyo/config/settings.toml`:

```toml
# Enable all Git plugins
enabled_plugins = ["git.*"]

# Or enable specific plugins
enabled_plugins = ["git.context", "git.filters"]
```

## Usage Examples

### Branch-Specific Rules

In your YAML rule files:

```yaml
code.review:
  when: Code review guidelines
  ruleset:
    - "{% if git_branch is on_branch('main') %}Code must pass all CI checks before merging{% endif %}"
    - "{% if git_branch is on_branch('main') %}Require code review from at least 2 reviewers{% endif %}"
    - "{% if git_branch is on_branch('develop') %}Code must pass unit tests{% endif %}"
    - "{% if git_branch is on_branch('develop') %}Require code review from at least 1 reviewer{% endif %}"
```

### Commit Information

```yaml
git.info:
  when: Git commit information
  ruleset:
    - "Current commit: {{ git_commit }}"
    - "Author: {{ git_author }} <{{ git_author_email }}>"
    - "{% if git_tag %}This is a tagged release: {{ git_tag }}{% endif %}"
```

### Clean Repository Checks

```yaml
git.status:
  when: Repository status checks
  ruleset:
    - "{% if not (git_is_clean is is_clean) %}Warning: You have uncommitted changes{% endif %}"
    - "{% if not (git_is_clean is is_clean) %}Please commit or stash your changes before proceeding{% endif %}"
```

### Remote Configuration

```yaml
git.remote:
  when: Remote repository configuration
  ruleset:
    - "{% if git_remote %}Remote: {{ git_remote_name }} ({{ git_remote }}){% endif %}"
    - "{% if not git_remote %}No remote configured - remember to push your changes{% endif %}"
```

## Availability

This plugin is only available when:

1. GitPython is installed
2. Running inside a Git repository

If GitPython is not installed or not in a Git repository, the plugin will gracefully disable itself.

## License

MIT License - see LICENSE file for details.

## Support

For issues and questions, visit the [Daimyo issue tracker](https://gitlab.com/Kencho1/daimyo/-/issues).
