Metadata-Version: 2.4
Name: jinja2-git-dir
Version: 0.4.1
Summary: Jinja2 filter extension for detecting if a directory is a git repository
Project-URL: repository, https://github.com/gordon-code/jinja2-git-dir/
Author-email: Will Gordon <will@gordoncode.dev>
License: MIT License
        
        Copyright (c) 2025 Gordon Code LLC
        
        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: copier,extension,filters,jinja,jinja2
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: Typing :: Typed
Requires-Python: >=3.9
Requires-Dist: jinja2>=3.0
Description-Content-Type: text/markdown

# Git Directory Extension

Jinja2 filter extension for detecting if a directory is an (empty) git repository.

## Usage

### `gitdir`

Detects if the path being filtered by `gitdir` is the _top level_ git repository directory.

So, if my path is `/git/path/here` and there exists `/git/path/here/.git`, 
then `{{ '/git/path/here' | gitdir }}` will be true.

However, if my path is `/git/path/here` and there exists `/git/path/.git`, 
then `{{ '/git/path/here' | gitdir }}` will be false.

This is because the _top level_ directory is `/git/path`, not the tested path of `/git/path/here`.


Examples:

- Detect if `git_path` is a git directory  
    `{{ git_path | gitdir }}`
- Assert that `git_path` is a git directory  
    `{{ git_path | gitdir is true }}`
- Assert that `git_path` is **NOT** a git directory  
    `{{ git_path | gitdir is false }}`
- Using `gitdir` in a conditional  
    `{% if (git_path | gitdir) %}{{ git_path }} is a git directory{% else %}no git directory at {{ git_path }}{% endif %}`


### `emptygit`

Detects if the path being filtered by `emptygit` contains exactly 0 commits across all references. 
This will work for subdirectories within a git directory.

So, if my path is `/git/path/here` and there have been *no* commits, then `{{ '/git/path/here' | emptygit }}` will be true.

However, if my path is `/git/path/here` and there *have* been _any_ commits anywhere, then `{{ '/git/path/here' | emptygit }}` will be false.


Examples:

- Detect if `git_path` is an empty git directory  
    `{{ git_path | emptygit }}`
- Assert that `git_path` is an empty git directory  
    `{{ git_path | emptygit is true }}`
- Assert that `git_path` is **NOT** an empty git directory  
    `{{ git_path | emptygit is false }}`
- Using `emptygit` in a conditional  
    `{% if (git_path | emptygit) %}{{ git_path }} has commits{% else %}{{ git_path }} has NO commits{% endif %}`

### Copier

This can be utilized within a Copier `copier.yaml` file for determining if the destination
path is already initialized as a git directory.

Example:  

This will configure a Copier `_task` to run `git init` but _only_ if the destination
path isn't already a git directory.

```yaml
_jinja_extensions:
    - jinja2_git_dir.GitDirectoryExtension
_tasks:
  - command: "git init"
    when: "{{ _copier_conf.dst_path | realpath | gitdir is false }}"
  # `emptygit is false` test must come first, otherwise both tasks trigger
  - command: "git commit -am 'template update applied'"
    when: "{{ _copier_conf.dst_path | realpath | emptygit is false }}"
  - command: "git commit -am 'initial commit'"
    when: "{{ _copier_conf.dst_path | realpath | emptygit is true }}"
```

## Development

- Use [`cog commit`](https://docs.cocogitto.io/guide/commit.html) for [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/)
-- `cog commit -a feat "new thing"`
- Use [`cog bump`](https://docs.cocogitto.io/guide/bump.html) for [SemVer versioning](https://semver.org)
-- `cog bump --auto`
- Use [`hatch build`](https://hatch.pypa.io/dev/cli/reference/#hatch-build) for building new package releases _after_ the repo version has been bumped
-- `uvx hatch build`
- Use [`hatch publish`](https://hatch.pypa.io/dev/cli/reference/#hatch-publish) to push the new package to PyPI
-- `uvx hatch publish`
- Bump the nixpkgs release to the new version
-- https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/python-modules/jinja2-git-dir/default.nix