git_alert 0.1.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Simon Antonius Lauer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,96 @@
1
+ Metadata-Version: 2.1
2
+ Name: git_alert
3
+ Version: 0.1.0
4
+ Summary: Checks a given path and its sub-directories for dirty git repositories.
5
+ License: MIT
6
+ Author: Simon Antonius Lauer
7
+ Author-email: simon.lauer@posteo.de
8
+ Requires-Python: >=3.11,<4.0
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Description-Content-Type: text/markdown
14
+
15
+ # Git Alert
16
+
17
+ <hr>
18
+
19
+ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
20
+ ![Codecov](https://img.shields.io/codecov/c/github/nomisreual/git_alert)
21
+
22
+ This is a Python application that checks in the given directory and all its subdirectories
23
+ for any dirty repositories.
24
+
25
+ This application aims to ease the frequent use of git as it makes it easy to check for any untracked changes in any of your repositories.
26
+
27
+ ## Installation:
28
+
29
+ The application is now available on PyPI, so you can install it using pip:
30
+
31
+ ```
32
+ pip install git_alert
33
+ ```
34
+
35
+ Alternatively, you can use pipx to make it globally available:
36
+
37
+ ```
38
+ pipx install git_alert
39
+ ```
40
+
41
+ Of course you can also clone the repository and install it manually. The package is built using poetry, so the easiest way to build it locally would be
42
+ to use poetry:
43
+
44
+ ```
45
+ git clone https://github.com/nomisreual/git_alert.git
46
+ cd git_alert
47
+ poetry build
48
+ ```
49
+
50
+ After the build, you can install it either using pip or pipx:
51
+
52
+ ```
53
+ pip install -e .
54
+ ```
55
+
56
+ or
57
+
58
+ ```
59
+ pipx install .
60
+ ```
61
+
62
+ ## Usage:
63
+
64
+ You can use _git_alert_ by either calling it as a module (`python -m git_alert`) or by directly using the installed package:
65
+
66
+ ```
67
+ usage: git_alert [-h] [--path PATH] [--only_dirty]
68
+
69
+ options:
70
+ -h, --help show this help message and exit
71
+ --path PATH top level directory to start the search in
72
+ --only_dirty only show dirty repositories in the final report
73
+ ```
74
+
75
+ ## Development:
76
+
77
+ The tool is aimed to be improved and extended going forward. If you have any ideas or want to contribute, feel free to open an issue or a pull request.
78
+
79
+ ## Goals:
80
+
81
+ - [ ] more detailed checks (currently it distinguishes only between a repository being clean or not)
82
+ - [ ] speed up the lookup process
83
+ - [ ] enable caching found repositories for faster checking after the first run (maybe utilizing a database)
84
+ - [ ] GUI interface
85
+
86
+ ## Contributing:
87
+
88
+ This project is under active development, so any contributions are welcome. Feel free to open an issue or a pull request.
89
+
90
+ In case you want to submit a pull request, please:
91
+
92
+ - make sure to run the tests before submission
93
+ - use black for code formatting
94
+
95
+ The project uses pre-commit hooks to ensure code quality, so feel free to use them as well.
96
+
@@ -0,0 +1,81 @@
1
+ # Git Alert
2
+
3
+ <hr>
4
+
5
+ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
6
+ ![Codecov](https://img.shields.io/codecov/c/github/nomisreual/git_alert)
7
+
8
+ This is a Python application that checks in the given directory and all its subdirectories
9
+ for any dirty repositories.
10
+
11
+ This application aims to ease the frequent use of git as it makes it easy to check for any untracked changes in any of your repositories.
12
+
13
+ ## Installation:
14
+
15
+ The application is now available on PyPI, so you can install it using pip:
16
+
17
+ ```
18
+ pip install git_alert
19
+ ```
20
+
21
+ Alternatively, you can use pipx to make it globally available:
22
+
23
+ ```
24
+ pipx install git_alert
25
+ ```
26
+
27
+ Of course you can also clone the repository and install it manually. The package is built using poetry, so the easiest way to build it locally would be
28
+ to use poetry:
29
+
30
+ ```
31
+ git clone https://github.com/nomisreual/git_alert.git
32
+ cd git_alert
33
+ poetry build
34
+ ```
35
+
36
+ After the build, you can install it either using pip or pipx:
37
+
38
+ ```
39
+ pip install -e .
40
+ ```
41
+
42
+ or
43
+
44
+ ```
45
+ pipx install .
46
+ ```
47
+
48
+ ## Usage:
49
+
50
+ You can use _git_alert_ by either calling it as a module (`python -m git_alert`) or by directly using the installed package:
51
+
52
+ ```
53
+ usage: git_alert [-h] [--path PATH] [--only_dirty]
54
+
55
+ options:
56
+ -h, --help show this help message and exit
57
+ --path PATH top level directory to start the search in
58
+ --only_dirty only show dirty repositories in the final report
59
+ ```
60
+
61
+ ## Development:
62
+
63
+ The tool is aimed to be improved and extended going forward. If you have any ideas or want to contribute, feel free to open an issue or a pull request.
64
+
65
+ ## Goals:
66
+
67
+ - [ ] more detailed checks (currently it distinguishes only between a repository being clean or not)
68
+ - [ ] speed up the lookup process
69
+ - [ ] enable caching found repositories for faster checking after the first run (maybe utilizing a database)
70
+ - [ ] GUI interface
71
+
72
+ ## Contributing:
73
+
74
+ This project is under active development, so any contributions are welcome. Feel free to open an issue or a pull request.
75
+
76
+ In case you want to submit a pull request, please:
77
+
78
+ - make sure to run the tests before submission
79
+ - use black for code formatting
80
+
81
+ The project uses pre-commit hooks to ensure code quality, so feel free to use them as well.
@@ -0,0 +1,3 @@
1
+ from git_alert.argument_parser import argument_parser
2
+ from git_alert.repositories import Repositories
3
+ from git_alert.traverse import GitAlert
@@ -0,0 +1,14 @@
1
+ import sys
2
+
3
+ from git_alert.argument_parser import argument_parser
4
+ from git_alert.repositories import Repositories
5
+ from git_alert.traverse import GitAlert
6
+
7
+ repos = Repositories()
8
+
9
+ args = argument_parser(sys.argv[1:])
10
+
11
+ alert = GitAlert(args.path, repos)
12
+
13
+ alert.traverse(args.path)
14
+ alert.repos.display(only_dirty=args.only_dirty)
@@ -0,0 +1,23 @@
1
+ from argparse import ArgumentParser, Namespace
2
+ from pathlib import Path
3
+
4
+
5
+ def argument_parser(args) -> Namespace:
6
+ """
7
+ Create argument parser providing two arguments:
8
+ --path: Path, default: Path.cwd()
9
+ --only_dirty: bool, default: False
10
+ """
11
+ parser = ArgumentParser()
12
+ parser.add_argument(
13
+ "--path",
14
+ type=Path,
15
+ default=Path.cwd(),
16
+ help="top level directory to start the search in",
17
+ )
18
+ parser.add_argument(
19
+ "--only_dirty",
20
+ action="store_true",
21
+ help="only show dirty repositories in the final report",
22
+ )
23
+ return parser.parse_args(args)
@@ -0,0 +1,26 @@
1
+ from pathlib import Path
2
+
3
+
4
+ class Repositories:
5
+ def __init__(self) -> None:
6
+ self.repos: list[dict[Path, str]] = []
7
+
8
+ def add_repo(self, repo: dict[Path, str]) -> None:
9
+ """
10
+ Add a repository to the list of repositories.
11
+ args:
12
+ repo: dict[Path, str]
13
+ """
14
+ self.repos.append(repo)
15
+
16
+ def display(self, only_dirty: bool) -> None:
17
+ """
18
+ Display the repositories.
19
+ args:
20
+ only_dirty: bool
21
+ """
22
+ for repo in self.repos:
23
+ for key, value in repo.items():
24
+ if only_dirty and value == "clean":
25
+ continue
26
+ print(f"Repository: {key} is {value}")
@@ -0,0 +1,16 @@
1
+ import sys
2
+
3
+ from git_alert.argument_parser import argument_parser
4
+ from git_alert.repositories import Repositories
5
+ from git_alert.traverse import GitAlert
6
+
7
+
8
+ def run():
9
+ repos = Repositories()
10
+
11
+ args = argument_parser(sys.argv[1:])
12
+
13
+ alert = GitAlert(args.path, repos)
14
+
15
+ alert.traverse(args.path)
16
+ alert.repos.display(only_dirty=args.only_dirty)
@@ -0,0 +1,50 @@
1
+ # traverse.py
2
+ import subprocess
3
+ import sys
4
+ from pathlib import Path
5
+
6
+ from git_alert.repositories import Repositories
7
+
8
+
9
+ class GitAlert:
10
+ def __init__(self, pth: Path, repos: Repositories):
11
+ self._pth = pth
12
+ self._repos = repos
13
+
14
+ def traverse(self, pth: Path) -> None:
15
+ """
16
+ Traverse the directory and its subdirectories and check if it is a git repository.
17
+ args:
18
+ pth: Path
19
+ """
20
+ try:
21
+ files = pth.glob("*")
22
+ for file in files:
23
+ if file.is_dir() and file.name == ".git":
24
+ self.check(file)
25
+
26
+ elif file.is_dir():
27
+ self.traverse(file)
28
+ except PermissionError:
29
+ print(f"Warning: no access to: {pth}", file=sys.stderr)
30
+
31
+ def check(self, pth: Path) -> None:
32
+ """
33
+ Check if the git repository is clean or dirty.
34
+ args:
35
+ pth: Path
36
+ """
37
+ repo = {}
38
+ output = subprocess.run(
39
+ ["git", "status"], cwd=pth.parent, stdout=subprocess.PIPE
40
+ )
41
+ if "working tree clean" in output.stdout.decode():
42
+ repo[pth.parent] = "clean"
43
+ self._repos.add_repo(repo)
44
+ else:
45
+ repo[pth.parent] = "dirty"
46
+ self._repos.add_repo(repo)
47
+
48
+ @property
49
+ def repos(self) -> Repositories:
50
+ return self._repos
@@ -0,0 +1,35 @@
1
+ [tool.poetry]
2
+ name = "git_alert"
3
+ version = "0.1.0"
4
+ description = "Checks a given path and its sub-directories for dirty git repositories."
5
+ authors = ["Simon Antonius Lauer <simon.lauer@posteo.de>"]
6
+ readme = "README.md"
7
+ license = "MIT"
8
+ packages = [{include = "git_alert"}]
9
+
10
+ [tool.poetry.dependencies]
11
+ python = "^3.11"
12
+
13
+
14
+ [tool.poetry.group.test.dependencies]
15
+ pytest = "^8.1.1"
16
+ pytest-cov = "^5.0.0"
17
+
18
+
19
+ [tool.poetry.group.development.dependencies]
20
+ flake8 = "^7.0.0"
21
+ black = "^24.3.0"
22
+ pre-commit = "^3.7.0"
23
+
24
+
25
+ [tool.poetry.group.publish.dependencies]
26
+ badgie = "^0.12.0"
27
+ coverage = "^7.4.4"
28
+ coverage-badge = "^1.1.0"
29
+
30
+ [tool.poetry.scripts]
31
+ git_alert = "git_alert.scripts.git_alert:run"
32
+
33
+ [build-system]
34
+ requires = ["poetry-core"]
35
+ build-backend = "poetry.core.masonry.api"