gitbolt 0.0.0.dev1__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.
- gitbolt/__init__.py +18 -0
- gitbolt/_internal_init.py +18 -0
- gitbolt/add.py +652 -0
- gitbolt/base.py +333 -0
- gitbolt/exceptions.py +46 -0
- gitbolt/git_subprocess/__init__.py +14 -0
- gitbolt/git_subprocess/_internal_init.py +9 -0
- gitbolt/git_subprocess/add.py +484 -0
- gitbolt/git_subprocess/base.py +436 -0
- gitbolt/git_subprocess/constants.py +13 -0
- gitbolt/git_subprocess/exceptions.py +110 -0
- gitbolt/git_subprocess/impl/__init__.py +6 -0
- gitbolt/git_subprocess/impl/simple.py +185 -0
- gitbolt/git_subprocess/ls_tree.py +384 -0
- gitbolt/git_subprocess/runner/__init__.py +8 -0
- gitbolt/git_subprocess/runner/base.py +64 -0
- gitbolt/git_subprocess/runner/simple_impl.py +89 -0
- gitbolt/git_subprocess/utils.py +179 -0
- gitbolt/ls_tree.py +155 -0
- gitbolt/models.py +686 -0
- gitbolt/py.typed +0 -0
- gitbolt/utils.py +179 -0
- gitbolt-0.0.0.dev1.dist-info/METADATA +308 -0
- gitbolt-0.0.0.dev1.dist-info/RECORD +27 -0
- gitbolt-0.0.0.dev1.dist-info/WHEEL +5 -0
- gitbolt-0.0.0.dev1.dist-info/licenses/LICENSE +201 -0
- gitbolt-0.0.0.dev1.dist-info/top_level.txt +1 -0
gitbolt/base.py
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
interfaces related to processors specific to git commands.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from abc import abstractmethod
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Protocol, override, Unpack, Self, overload, Literal
|
|
13
|
+
|
|
14
|
+
from vt.utils.commons.commons.op import RootDirOp
|
|
15
|
+
from vt.utils.errors.error_specs import ERR_DATA_FORMAT_ERR
|
|
16
|
+
|
|
17
|
+
from gitbolt.exceptions import GitExitingException
|
|
18
|
+
from gitbolt.models import GitOpts, GitAddOpts, GitLsTreeOpts, GitEnvVars
|
|
19
|
+
from gitbolt.ls_tree import LsTreeArgsValidator, UtilLsTreeArgsValidator
|
|
20
|
+
from gitbolt.add import AddArgsValidator, UtilAddArgsValidator
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ForGit(Protocol):
|
|
24
|
+
"""
|
|
25
|
+
Marker interface to mark an operation for git.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class HasGitUnderneath[G: "Git"](ForGit, Protocol):
|
|
32
|
+
"""
|
|
33
|
+
Stores a reference to main git instance.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
@abstractmethod
|
|
38
|
+
def underlying_git(self) -> G:
|
|
39
|
+
"""
|
|
40
|
+
:return: stored git instance reference.
|
|
41
|
+
"""
|
|
42
|
+
...
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class CanOverrideGitOpts(ForGit, Protocol):
|
|
46
|
+
"""
|
|
47
|
+
Can override main git command options.
|
|
48
|
+
|
|
49
|
+
For example, in ``git --no-pager log -1 master`` git command, ``--no-pager`` is the main command arg.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
@abstractmethod
|
|
53
|
+
def git_opts_override(self, **overrides: Unpack[GitOpts]) -> Self:
|
|
54
|
+
"""
|
|
55
|
+
Temporarily override options to the main git command before current subcommand runs.
|
|
56
|
+
|
|
57
|
+
Get a new ``Git`` object with the git main command options overridden.
|
|
58
|
+
|
|
59
|
+
All the parameters mirror options described in the `git documentation <https://git-scm.com/docs/git>`_.
|
|
60
|
+
|
|
61
|
+
For example, in ``git --no-pager log -1 master`` git command, ``--no-pager`` is the main command arg.
|
|
62
|
+
|
|
63
|
+
:return: instance with overridden git main command args.
|
|
64
|
+
"""
|
|
65
|
+
...
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class CanOverrideGitEnvs(ForGit, Protocol):
|
|
69
|
+
"""
|
|
70
|
+
Can override main git command environment variables.
|
|
71
|
+
|
|
72
|
+
For example, in ``GIT_COMMITTER_NAME=vt git --no-pager commit -m "a message"`` git command,
|
|
73
|
+
``GIT_COMMITTER_NAME=ss``, particularly ``GIT_COMMITTER_NAME`` is the git environment variable.
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
@abstractmethod
|
|
77
|
+
def git_envs_override(self, **overrides: Unpack[GitEnvVars]) -> Self:
|
|
78
|
+
"""
|
|
79
|
+
Temporarily override environment variables supplied to the git command before current subcommand runs.
|
|
80
|
+
|
|
81
|
+
Get a new ``Git`` object with the git environment variables overridden.
|
|
82
|
+
|
|
83
|
+
All the environment variables mirror envs described in the `git documentation <https://git-scm.com/docs/git#_environment_variables>`_.
|
|
84
|
+
|
|
85
|
+
For example, in ``GIT_COMMITTER_NAME=vt git --no-pager commit -m "a message"`` git command,
|
|
86
|
+
``GIT_COMMITTER_NAME=vt``, particularly ``GIT_COMMITTER_NAME`` is the git environment variable.
|
|
87
|
+
|
|
88
|
+
:return: instance with overridden git environment variables.
|
|
89
|
+
"""
|
|
90
|
+
...
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class GitSubCommand(CanOverrideGitOpts, CanOverrideGitEnvs, Protocol):
|
|
94
|
+
"""
|
|
95
|
+
Interface for git subcommands, such as:
|
|
96
|
+
|
|
97
|
+
* ``add``
|
|
98
|
+
* ``commit``
|
|
99
|
+
* ``pull``
|
|
100
|
+
* ...
|
|
101
|
+
etc.
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
@abstractmethod
|
|
105
|
+
def clone(self) -> Self:
|
|
106
|
+
"""
|
|
107
|
+
:return: a clone of the underlying subcommand.
|
|
108
|
+
"""
|
|
109
|
+
...
|
|
110
|
+
|
|
111
|
+
@abstractmethod
|
|
112
|
+
def _subcmd_from_git(self, git: "Git") -> Self:
|
|
113
|
+
"""
|
|
114
|
+
Protected. Intended for inheritance only.
|
|
115
|
+
|
|
116
|
+
:return: specific implementation of subcommand from ``git``.
|
|
117
|
+
"""
|
|
118
|
+
...
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class LsTree(GitSubCommand, RootDirOp, Protocol):
|
|
122
|
+
"""
|
|
123
|
+
Interface for ``git ls-tree`` command.
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
@abstractmethod
|
|
127
|
+
def ls_tree(self, tree_ish: str, **ls_tree_opts: Unpack[GitLsTreeOpts]) -> str:
|
|
128
|
+
"""
|
|
129
|
+
All the parameters are mirrors of the parameters of ``git ls-tree`` CLI command
|
|
130
|
+
from `git ls-tree documentation <https://git-scm.com/docs/git-ls-tree>`_.
|
|
131
|
+
|
|
132
|
+
:param tree_ish: A tree-ish identifier (commit SHA, branch name, etc.).
|
|
133
|
+
:param ls_tree_opts: Keyword arguments mapping to supported options for ``git ls-tree``.
|
|
134
|
+
:return: ``ls-tree`` output.
|
|
135
|
+
"""
|
|
136
|
+
...
|
|
137
|
+
|
|
138
|
+
@override
|
|
139
|
+
def _subcmd_from_git(self, git: "Git") -> "LsTree":
|
|
140
|
+
return git.ls_tree_subcmd
|
|
141
|
+
|
|
142
|
+
@property
|
|
143
|
+
def args_validator(self) -> LsTreeArgsValidator:
|
|
144
|
+
"""
|
|
145
|
+
The argument validator for ``git ls-tree`` subcommand.
|
|
146
|
+
|
|
147
|
+
:return: a validator for ls_tree subcommand arguments.
|
|
148
|
+
"""
|
|
149
|
+
return UtilLsTreeArgsValidator()
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
class Add(GitSubCommand, RootDirOp, Protocol):
|
|
153
|
+
"""
|
|
154
|
+
Interface for ``git add`` command.
|
|
155
|
+
"""
|
|
156
|
+
|
|
157
|
+
@overload
|
|
158
|
+
@abstractmethod
|
|
159
|
+
def add(
|
|
160
|
+
self, pathspec: str, *pathspecs: str, **add_opts: Unpack[GitAddOpts]
|
|
161
|
+
) -> str:
|
|
162
|
+
"""
|
|
163
|
+
Add files specified by a list of pathspec strings.
|
|
164
|
+
`pathspec_from_file` and `pathspec_file_null` are disallowed here.
|
|
165
|
+
|
|
166
|
+
Mirrors the parameters of ``git add`` CLI command
|
|
167
|
+
from `git add documentation <https://git-scm.com/docs/git-add>`_.
|
|
168
|
+
|
|
169
|
+
:return: output of ``git add``.
|
|
170
|
+
"""
|
|
171
|
+
|
|
172
|
+
@overload
|
|
173
|
+
@abstractmethod
|
|
174
|
+
def add(
|
|
175
|
+
self,
|
|
176
|
+
*,
|
|
177
|
+
pathspec_from_file: Path,
|
|
178
|
+
pathspec_file_nul: bool = False,
|
|
179
|
+
**add_opts: Unpack[GitAddOpts],
|
|
180
|
+
) -> str:
|
|
181
|
+
"""
|
|
182
|
+
Add files listed in a file (`pathspec_from_file`) to the index.
|
|
183
|
+
`pathspec_file_null` indicates if the file is NUL terminated.
|
|
184
|
+
No explicit pathspec list is allowed in this overload.
|
|
185
|
+
|
|
186
|
+
Mirrors the parameters of ``git add`` CLI command
|
|
187
|
+
from `git add documentation <https://git-scm.com/docs/git-add>`_.
|
|
188
|
+
|
|
189
|
+
:return: output of ``git add``.
|
|
190
|
+
"""
|
|
191
|
+
|
|
192
|
+
@overload
|
|
193
|
+
@abstractmethod
|
|
194
|
+
def add(
|
|
195
|
+
self,
|
|
196
|
+
*,
|
|
197
|
+
pathspec_from_file: Literal["-"],
|
|
198
|
+
pathspec_stdin: str,
|
|
199
|
+
pathspec_file_nul: bool = False,
|
|
200
|
+
**add_opts: Unpack[GitAddOpts],
|
|
201
|
+
) -> str:
|
|
202
|
+
"""
|
|
203
|
+
Add files listed from stdin (when `pathspec_from_file` is '-').
|
|
204
|
+
The `pathspec_stdin` argument is the string content piped to stdin.
|
|
205
|
+
|
|
206
|
+
Mirrors the parameters of ``git add`` CLI command
|
|
207
|
+
from `git add documentation <https://git-scm.com/docs/git-add>`_.
|
|
208
|
+
|
|
209
|
+
:return: output of ``git add``.
|
|
210
|
+
"""
|
|
211
|
+
|
|
212
|
+
@property
|
|
213
|
+
def args_validator(self) -> AddArgsValidator:
|
|
214
|
+
"""
|
|
215
|
+
The argument validator for ``git add`` subcommand.
|
|
216
|
+
|
|
217
|
+
:return: a validator for add subcommand arguments.
|
|
218
|
+
"""
|
|
219
|
+
return UtilAddArgsValidator()
|
|
220
|
+
|
|
221
|
+
@override
|
|
222
|
+
def _subcmd_from_git(self, git: "Git") -> "Add":
|
|
223
|
+
return git.add_subcmd
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
class Version(GitSubCommand, Protocol):
|
|
227
|
+
"""
|
|
228
|
+
Interface for ``git version`` command.
|
|
229
|
+
"""
|
|
230
|
+
|
|
231
|
+
@abstractmethod
|
|
232
|
+
def version(self, build_options: bool = False) -> str:
|
|
233
|
+
"""
|
|
234
|
+
All the parameters are mirrors of the parameters of ``git version`` CLI command
|
|
235
|
+
from `git version documentation <https://git-scm.com/docs/git-version>`_.
|
|
236
|
+
|
|
237
|
+
:return: ``version`` output.
|
|
238
|
+
"""
|
|
239
|
+
...
|
|
240
|
+
|
|
241
|
+
@staticmethod
|
|
242
|
+
def _require_valid_args(build_options: bool = False) -> None:
|
|
243
|
+
"""
|
|
244
|
+
Require that arguments sent to the version command is valid.
|
|
245
|
+
|
|
246
|
+
:param build_options: argument to be validated.
|
|
247
|
+
:raise GitExitingException: if supplied ``build_options`` is invalid.
|
|
248
|
+
"""
|
|
249
|
+
if not isinstance(build_options, bool):
|
|
250
|
+
errmsg = "build_options should be bool."
|
|
251
|
+
raise GitExitingException(
|
|
252
|
+
errmsg, exit_code=ERR_DATA_FORMAT_ERR
|
|
253
|
+
) from TypeError(errmsg)
|
|
254
|
+
|
|
255
|
+
@override
|
|
256
|
+
def _subcmd_from_git(self, git: "Git") -> "Version":
|
|
257
|
+
return git.version_subcmd
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
class Git(CanOverrideGitOpts, CanOverrideGitEnvs, Protocol):
|
|
261
|
+
"""
|
|
262
|
+
Class designed analogous to documentation provided on `git documentation <https://git-scm.com/docs/git>`_.
|
|
263
|
+
"""
|
|
264
|
+
|
|
265
|
+
@property
|
|
266
|
+
def version(self) -> str:
|
|
267
|
+
"""
|
|
268
|
+
:return: current git version.
|
|
269
|
+
"""
|
|
270
|
+
return self.version_subcmd.version()
|
|
271
|
+
|
|
272
|
+
@property
|
|
273
|
+
@abstractmethod
|
|
274
|
+
def exec_path(self) -> Path:
|
|
275
|
+
"""
|
|
276
|
+
:return: Path to wherever your core Git programs are installed.
|
|
277
|
+
"""
|
|
278
|
+
...
|
|
279
|
+
|
|
280
|
+
@property
|
|
281
|
+
@abstractmethod
|
|
282
|
+
def html_path(self) -> Path:
|
|
283
|
+
"""
|
|
284
|
+
:return: the path, without trailing slash, where Git’s HTML documentation is installed.
|
|
285
|
+
"""
|
|
286
|
+
...
|
|
287
|
+
|
|
288
|
+
@property
|
|
289
|
+
@abstractmethod
|
|
290
|
+
def info_path(self) -> Path:
|
|
291
|
+
"""
|
|
292
|
+
:return: the path where the Info files documenting this version of Git are installed.
|
|
293
|
+
"""
|
|
294
|
+
...
|
|
295
|
+
|
|
296
|
+
@property
|
|
297
|
+
@abstractmethod
|
|
298
|
+
def man_path(self) -> Path:
|
|
299
|
+
"""
|
|
300
|
+
:return: the man path (see man(1)) for the man pages for this version of Git.
|
|
301
|
+
"""
|
|
302
|
+
...
|
|
303
|
+
|
|
304
|
+
@property
|
|
305
|
+
@abstractmethod
|
|
306
|
+
def version_subcmd(self) -> Version:
|
|
307
|
+
"""
|
|
308
|
+
:return: ``git version`` subcommand.
|
|
309
|
+
"""
|
|
310
|
+
...
|
|
311
|
+
|
|
312
|
+
@property
|
|
313
|
+
@abstractmethod
|
|
314
|
+
def ls_tree_subcmd(self) -> LsTree:
|
|
315
|
+
"""
|
|
316
|
+
:return: ``git ls-tree`` subcommand.
|
|
317
|
+
"""
|
|
318
|
+
...
|
|
319
|
+
|
|
320
|
+
@property
|
|
321
|
+
@abstractmethod
|
|
322
|
+
def add_subcmd(self) -> Add:
|
|
323
|
+
"""
|
|
324
|
+
:return: ``git add`` subcommand.
|
|
325
|
+
"""
|
|
326
|
+
...
|
|
327
|
+
|
|
328
|
+
@abstractmethod
|
|
329
|
+
def clone(self) -> Self:
|
|
330
|
+
"""
|
|
331
|
+
:return: a clone of this class.
|
|
332
|
+
"""
|
|
333
|
+
...
|
gitbolt/exceptions.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Exceptions specific to git.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from vt.utils.errors.error_specs.exceptions import VTException, VTExitingException
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class GitException(VTException):
|
|
12
|
+
"""
|
|
13
|
+
``VTException`` specific to git.
|
|
14
|
+
|
|
15
|
+
Examples:
|
|
16
|
+
|
|
17
|
+
* raise exception:
|
|
18
|
+
|
|
19
|
+
>>> raise GitException()
|
|
20
|
+
Traceback (most recent call last):
|
|
21
|
+
gitbolt.exceptions.GitException
|
|
22
|
+
|
|
23
|
+
* raise exception with a message:
|
|
24
|
+
|
|
25
|
+
>>> raise GitException('unexpected.')
|
|
26
|
+
Traceback (most recent call last):
|
|
27
|
+
gitbolt.exceptions.GitException: unexpected.
|
|
28
|
+
|
|
29
|
+
* raise exception from another exception:
|
|
30
|
+
|
|
31
|
+
>>> raise GitException() from ValueError
|
|
32
|
+
Traceback (most recent call last):
|
|
33
|
+
gitbolt.exceptions.GitException: ValueError
|
|
34
|
+
|
|
35
|
+
... rest examples mimic ``VTException`` examples.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class GitExitingException(GitException, VTExitingException):
|
|
42
|
+
"""
|
|
43
|
+
``GitException`` that carries an ``exit_code``.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
pass
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Git command interfaces with implementation using subprocess calls.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
# region gitbolt.git_subprocess.base
|
|
9
|
+
from gitbolt.git_subprocess.base import GitCommand as GitCommand
|
|
10
|
+
from gitbolt.git_subprocess.base import GitSubcmdCommand as GitSubcmdCommand
|
|
11
|
+
from gitbolt.git_subprocess.base import AddCommand as AddCommand
|
|
12
|
+
from gitbolt.git_subprocess.base import LsTreeCommand as LsTreeCommand
|
|
13
|
+
from gitbolt.git_subprocess.base import VersionCommand as VersionCommand
|
|
14
|
+
# endregion
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Git command interfaces with implementation using subprocess calls.
|
|
6
|
+
|
|
7
|
+
This file is created to behave as an __init__ but only for internal stuff as we do not want to export everything
|
|
8
|
+
in the package's __init__.
|
|
9
|
+
"""
|