Jinja2 filter extension for detecting if a directory is a git repository
Project description
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_pathis a git directory
{{ git_path | gitdir }} - Assert that
git_pathis a git directory
{{ git_path | gitdir is true }} - Assert that
git_pathis NOT a git directory
{{ git_path | gitdir is false }} - Using
gitdirin 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_pathis an empty git directory
{{ git_path | emptygit }} - Assert that
git_pathis an empty git directory
{{ git_path | emptygit is true }} - Assert that
git_pathis NOT an empty git directory
{{ git_path | emptygit is false }} - Using
emptygitin 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.
_jinja_extensions:
- jinja2_git_dir.GitDirectoryExtension
_tasks:
- command: "git init"
when: "{{ _copier_conf.dst_path | realpath | gitdir is false }}"
- command: "git commit -am 'initial commit'"
when: "{{ _copier_conf.dst_path | realpath | emptygit is true }}"
Development
- Use
cog commitfor conventional commits --cog commit -a feat "new thing" - Use
cog bumpfor SemVer versioning --cog bump --auto - Use
hatch buildfor building new package releases after the repo version has been bumped --uvx hatch build - Use
hatch publishto 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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jinja2_git_dir-0.4.0.tar.gz.
File metadata
- Download URL: jinja2_git_dir-0.4.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b1b331807c5d5dc393bca7e17e28e7dac6b545449ed5c3b17d640cd80f3b085
|
|
| MD5 |
de834e8d1e15e6a346f044f5c49a7fb0
|
|
| BLAKE2b-256 |
8171c917582f4de59557f27100ff3bc49821b32c9b399f230d93a5b7708c54b5
|
File details
Details for the file jinja2_git_dir-0.4.0-py3-none-any.whl.
File metadata
- Download URL: jinja2_git_dir-0.4.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2053487390ce4b74e835f05d5f8c79917b0a116a9b3c52d46a8380080a5148c8
|
|
| MD5 |
567fb7e3db82baa2214ed63328098491
|
|
| BLAKE2b-256 |
37fc5f141d6e1db1c6521add2d1bb7536b744d09b5d3862413b0d1747112040b
|