githead 1.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- githead/__init__.py +33 -0
- githead/py.typed +0 -0
- githead-1.2.0.dist-info/LICENSE +24 -0
- githead-1.2.0.dist-info/METADATA +47 -0
- githead-1.2.0.dist-info/RECORD +7 -0
- githead-1.2.0.dist-info/WHEEL +5 -0
- githead-1.2.0.dist-info/top_level.txt +1 -0
githead/__init__.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from os import PathLike
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def githead(git_dir: PathLike[str] | str = '.git') -> str:
|
|
11
|
+
"""Get the current git commit hash.
|
|
12
|
+
|
|
13
|
+
>>> githead()
|
|
14
|
+
'bca663418428d603eea8243d08a5ded19eb19a34'
|
|
15
|
+
"""
|
|
16
|
+
dir_path = Path(git_dir)
|
|
17
|
+
head_path = dir_path.joinpath('HEAD')
|
|
18
|
+
head = head_path.read_text().strip()
|
|
19
|
+
|
|
20
|
+
is_symbolic = head.startswith('ref: ')
|
|
21
|
+
if not is_symbolic:
|
|
22
|
+
return head
|
|
23
|
+
|
|
24
|
+
dir_abs = dir_path.resolve()
|
|
25
|
+
ref_abs = dir_abs.joinpath(head[5:]).resolve()
|
|
26
|
+
if not ref_abs.is_relative_to(dir_abs):
|
|
27
|
+
raise ValueError(f'HEAD references outside of {git_dir} directory')
|
|
28
|
+
|
|
29
|
+
ref = ref_abs.read_text().strip()
|
|
30
|
+
return ref
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
__all__ = ('githead',)
|
githead/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
|
2
|
+
|
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
4
|
+
distribute this software, either in source code form or as a compiled
|
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
|
6
|
+
means.
|
|
7
|
+
|
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
|
9
|
+
of this software dedicate any and all copyright interest in the
|
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
|
11
|
+
of the public at large and to the detriment of our heirs and
|
|
12
|
+
successors. We intend this dedication to be an overt act of
|
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
|
14
|
+
software under copyright law.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
For more information, please refer to <https://unlicense.org>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: githead
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: Simple utility for getting the current git commit hash (HEAD)
|
|
5
|
+
Author-email: Kamil Monicz <kamil@monicz.dev>
|
|
6
|
+
Project-URL: Issues, https://github.com/Zaczero/githead/issues
|
|
7
|
+
Project-URL: Repository, https://github.com/Zaczero/githead
|
|
8
|
+
Keywords: commit,git,git-commit,hash,head,vcs,version-control
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: The Unlicense (Unlicense)
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
|
|
24
|
+
# githead
|
|
25
|
+
|
|
26
|
+
[](https://pypi.org/project/githead)
|
|
27
|
+
[](https://liberapay.com/Zaczero/)
|
|
28
|
+
[](https://github.com/sponsors/Zaczero)
|
|
29
|
+
|
|
30
|
+
Simple utility for getting the current git commit hash (HEAD).
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
pip install githead
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Basic usage
|
|
39
|
+
|
|
40
|
+
```py
|
|
41
|
+
from githead import githead
|
|
42
|
+
|
|
43
|
+
githead() # -> 'bca663418428d603eea8243d08a5ded19eb19a34'
|
|
44
|
+
|
|
45
|
+
# defaults to '.git' directory but can be changed:
|
|
46
|
+
githead('path/to/.git')
|
|
47
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
githead/__init__.py,sha256=fOhezQL9aKdxz2VlwufCBhjQfwayRjjAJ9ASiRht6Qk,800
|
|
2
|
+
githead/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
githead-1.2.0.dist-info/LICENSE,sha256=awOCsWJ58m_2kBQwBUGWejVqZm6wuRtCL2hi9rfa0X4,1211
|
|
4
|
+
githead-1.2.0.dist-info/METADATA,sha256=30fMx4VaPGhJhTWyMGTki2gmMN1YyLGZRBxesIf32Aw,1723
|
|
5
|
+
githead-1.2.0.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
|
|
6
|
+
githead-1.2.0.dist-info/top_level.txt,sha256=2-OzsM5AJpcpJbfK3Fade0qcp9DxlYUI2n_3uHmljj0,8
|
|
7
|
+
githead-1.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
githead
|