gitbolt 0.0.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.
- gitbolt/__init__.py +97 -0
- gitbolt/_internal_init.py +18 -0
- gitbolt/add.py +652 -0
- gitbolt/base.py +983 -0
- gitbolt/constants.py +12 -0
- gitbolt/exceptions.py +46 -0
- gitbolt/hash_object.py +263 -0
- gitbolt/ls_tree.py +155 -0
- gitbolt/models.py +698 -0
- gitbolt/py.typed +0 -0
- gitbolt/pytest_plugin.py +41 -0
- gitbolt/subprocess/__init__.py +18 -0
- gitbolt/subprocess/_internal_init.py +9 -0
- gitbolt/subprocess/add.py +484 -0
- gitbolt/subprocess/base.py +1835 -0
- gitbolt/subprocess/constants.py +23 -0
- gitbolt/subprocess/exceptions.py +110 -0
- gitbolt/subprocess/hash_object.py +227 -0
- gitbolt/subprocess/hash_object_util.py +90 -0
- gitbolt/subprocess/impl/__init__.py +6 -0
- gitbolt/subprocess/impl/simple.py +613 -0
- gitbolt/subprocess/ls_tree.py +406 -0
- gitbolt/subprocess/runner/__init__.py +8 -0
- gitbolt/subprocess/runner/base.py +106 -0
- gitbolt/subprocess/runner/simple.py +150 -0
- gitbolt/subprocess/utils/__init__.py +6 -0
- gitbolt/subprocess/utils/main_cmd.py +216 -0
- gitbolt/subprocess/utils/models.py +97 -0
- gitbolt/subprocess/utils/session.py +610 -0
- gitbolt/subprocess/worktree.py +266 -0
- gitbolt/utils.py +215 -0
- gitbolt-0.0.0.dist-info/METADATA +464 -0
- gitbolt-0.0.0.dist-info/RECORD +37 -0
- gitbolt-0.0.0.dist-info/WHEEL +5 -0
- gitbolt-0.0.0.dist-info/entry_points.txt +2 -0
- gitbolt-0.0.0.dist-info/licenses/LICENSE +201 -0
- gitbolt-0.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Helper interfaces for ``git ls-tree`` subcommand with default implementation for subprocess calls.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from abc import abstractmethod
|
|
9
|
+
from typing import Protocol, Unpack, override
|
|
10
|
+
|
|
11
|
+
from gitbolt.subprocess.constants import LS_TREE_CMD
|
|
12
|
+
from gitbolt.models import GitLsTreeOpts
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class LsTreeCLIArgsBuilder(Protocol):
|
|
16
|
+
"""
|
|
17
|
+
Interface to facilitate building of cli arguments for ``git ls-tree`` subcommand.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
@abstractmethod
|
|
21
|
+
def build(self, tree_ish: str, **ls_tree_opts: Unpack[GitLsTreeOpts]) -> list[str]:
|
|
22
|
+
"""
|
|
23
|
+
Build the complete list of subcommand arguments to be passed to ``git ls-tree``.
|
|
24
|
+
|
|
25
|
+
This method assembles the subcommand portion of the git command invocation, such as
|
|
26
|
+
in ``git --no-pager ls-tree -r HEAD``, where ``-r HEAD`` is the subcommand argument list.
|
|
27
|
+
|
|
28
|
+
It delegates the formation of each argument to protected helper methods to allow
|
|
29
|
+
easier overriding and testing of individual components.
|
|
30
|
+
|
|
31
|
+
Includes support for:
|
|
32
|
+
|
|
33
|
+
- Boolean flags (e.g., -r, -t, --name-only)
|
|
34
|
+
- Optional key-value arguments (e.g., --abbrev=N, --format=FMT)
|
|
35
|
+
- Required tree-ish identifier
|
|
36
|
+
- Optional file path list
|
|
37
|
+
|
|
38
|
+
:param tree_ish: A tree-ish identifier (commit SHA, branch name, etc.).
|
|
39
|
+
:param ls_tree_opts: Keyword arguments mapping to supported options for ``git ls-tree``.
|
|
40
|
+
:return: Complete list of subcommand arguments.
|
|
41
|
+
:raises GitExitingException: if undesired argument type or argument combination is supplied.
|
|
42
|
+
"""
|
|
43
|
+
...
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class IndividuallyOverridableLTCAB(LsTreeCLIArgsBuilder):
|
|
47
|
+
"""
|
|
48
|
+
Individually Overridable Ls Tree CLI Args Builder.
|
|
49
|
+
|
|
50
|
+
Build CLI args to run ``git ls-tree`` subcommand in a subprocess. This class is independent in its working and
|
|
51
|
+
provides interface to individually override each arg former for fine-grained control.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
@override
|
|
55
|
+
def build(self, tree_ish: str, **ls_tree_opts: Unpack[GitLsTreeOpts]) -> list[str]:
|
|
56
|
+
"""
|
|
57
|
+
Build the full list of arguments to be passed to ``git ls-tree``.
|
|
58
|
+
|
|
59
|
+
This includes flags, optional arguments, tree-ish identifier, and optional paths.
|
|
60
|
+
|
|
61
|
+
>>> builder = IndividuallyOverridableLTCAB()
|
|
62
|
+
|
|
63
|
+
* Basic case: only tree-ish::
|
|
64
|
+
|
|
65
|
+
>>> builder.build("HEAD")
|
|
66
|
+
['ls-tree', 'HEAD']
|
|
67
|
+
|
|
68
|
+
* With single boolean option::
|
|
69
|
+
|
|
70
|
+
>>> builder.build("HEAD", r=True)
|
|
71
|
+
['ls-tree', '-r', 'HEAD']
|
|
72
|
+
|
|
73
|
+
* With multiple boolean flags::
|
|
74
|
+
|
|
75
|
+
>>> builder.build("HEAD", r=True, t=True, d=True)
|
|
76
|
+
['ls-tree', '-d', '-r', '-t', 'HEAD']
|
|
77
|
+
|
|
78
|
+
* Long listing format::
|
|
79
|
+
|
|
80
|
+
>>> builder.build("HEAD", long=True)
|
|
81
|
+
['ls-tree', '-l', 'HEAD']
|
|
82
|
+
|
|
83
|
+
* All common flags::
|
|
84
|
+
|
|
85
|
+
>>> builder.build("HEAD", r=True, t=True, long=True, z=True,
|
|
86
|
+
... name_only=True, full_name=True, full_tree=True)
|
|
87
|
+
['ls-tree', '-r', '-t', '-l', '-z', '--name-only', '--full-name', '--full-tree', 'HEAD']
|
|
88
|
+
|
|
89
|
+
* With --name-status::
|
|
90
|
+
|
|
91
|
+
>>> builder.build("HEAD", name_status=True)
|
|
92
|
+
['ls-tree', '--name-status', 'HEAD']
|
|
93
|
+
|
|
94
|
+
* With --object-only::
|
|
95
|
+
|
|
96
|
+
>>> builder.build("HEAD", object_only=True)
|
|
97
|
+
['ls-tree', '--object-only', 'HEAD']
|
|
98
|
+
|
|
99
|
+
* With --abbrev (edge cases)::
|
|
100
|
+
|
|
101
|
+
>>> builder.build("HEAD", abbrev=0)
|
|
102
|
+
['ls-tree', '--abbrev=0', 'HEAD']
|
|
103
|
+
>>> builder.build("HEAD", abbrev=40)
|
|
104
|
+
['ls-tree', '--abbrev=40', 'HEAD']
|
|
105
|
+
>>> builder.build("HEAD", abbrev=7)
|
|
106
|
+
['ls-tree', '--abbrev=7', 'HEAD']
|
|
107
|
+
|
|
108
|
+
* With --format::
|
|
109
|
+
|
|
110
|
+
>>> builder.build("HEAD", format_="%(objectname)")
|
|
111
|
+
['ls-tree', '--format', '%(objectname)', 'HEAD']
|
|
112
|
+
|
|
113
|
+
>>> builder.build("HEAD", format_="")
|
|
114
|
+
['ls-tree', '--format', '', 'HEAD']
|
|
115
|
+
|
|
116
|
+
>>> builder.build("HEAD", format_="''")
|
|
117
|
+
['ls-tree', '--format', "''", 'HEAD']
|
|
118
|
+
|
|
119
|
+
>>> builder.build("HEAD", format_='""')
|
|
120
|
+
['ls-tree', '--format', '""', 'HEAD']
|
|
121
|
+
|
|
122
|
+
>>> builder.build("HEAD", format_="%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)")
|
|
123
|
+
['ls-tree', '--format', '%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)', 'HEAD']
|
|
124
|
+
|
|
125
|
+
>>> builder.build("HEAD", format_="'%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)'")
|
|
126
|
+
['ls-tree', '--format', "'%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)'", 'HEAD']
|
|
127
|
+
|
|
128
|
+
>>> builder.build("HEAD", format_='"%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)"')
|
|
129
|
+
['ls-tree', '--format', '"%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)"', 'HEAD']
|
|
130
|
+
|
|
131
|
+
* With paths::
|
|
132
|
+
|
|
133
|
+
>>> builder.build("HEAD", path=["src", "README.md"])
|
|
134
|
+
['ls-tree', 'HEAD', 'src', 'README.md']
|
|
135
|
+
|
|
136
|
+
* With flags and paths::
|
|
137
|
+
|
|
138
|
+
>>> builder.build("HEAD", r=True, path=["src/module.py"])
|
|
139
|
+
['ls-tree', '-r', 'HEAD', 'src/module.py']
|
|
140
|
+
|
|
141
|
+
* All supported options::
|
|
142
|
+
|
|
143
|
+
>>> builder.build(
|
|
144
|
+
... "HEAD",
|
|
145
|
+
... d=True,
|
|
146
|
+
... r=True,
|
|
147
|
+
... t=True,
|
|
148
|
+
... long=True,
|
|
149
|
+
... z=True,
|
|
150
|
+
... name_only=True,
|
|
151
|
+
... name_status=False,
|
|
152
|
+
... object_only=True,
|
|
153
|
+
... full_name=True,
|
|
154
|
+
... full_tree=True,
|
|
155
|
+
... abbrev=10,
|
|
156
|
+
... format_="%(objectname) %(path)",
|
|
157
|
+
... path=["dir1", "dir2/file.txt"]
|
|
158
|
+
... )
|
|
159
|
+
['ls-tree', '-d', '-r', '-t', '-l', '-z', '--name-only', '--object-only', '--full-name', '--full-tree', '--abbrev=10', '--format', '%(objectname) %(path)', 'HEAD', 'dir1', 'dir2/file.txt']
|
|
160
|
+
|
|
161
|
+
* Empty or falsy values, mostly will fail at validation::
|
|
162
|
+
|
|
163
|
+
>>> builder.build("HEAD", d=False,
|
|
164
|
+
... abbrev=None, # type: ignore[arg-type] # expected int provided None
|
|
165
|
+
... path=[],
|
|
166
|
+
... format_=None) # type: ignore[arg-type] # expected str provided None
|
|
167
|
+
['ls-tree', 'HEAD']
|
|
168
|
+
"""
|
|
169
|
+
sub_cmd_args = [LS_TREE_CMD]
|
|
170
|
+
|
|
171
|
+
sub_cmd_args.extend(self.d_arg(ls_tree_opts.get("d")))
|
|
172
|
+
sub_cmd_args.extend(self.r_arg(ls_tree_opts.get("r")))
|
|
173
|
+
sub_cmd_args.extend(self.t_arg(ls_tree_opts.get("t")))
|
|
174
|
+
sub_cmd_args.extend(self.long_arg(ls_tree_opts.get("long")))
|
|
175
|
+
sub_cmd_args.extend(self.z_arg(ls_tree_opts.get("z")))
|
|
176
|
+
sub_cmd_args.extend(self.name_only_arg(ls_tree_opts.get("name_only")))
|
|
177
|
+
sub_cmd_args.extend(self.name_status_arg(ls_tree_opts.get("name_status")))
|
|
178
|
+
sub_cmd_args.extend(self.object_only_arg(ls_tree_opts.get("object_only")))
|
|
179
|
+
sub_cmd_args.extend(self.full_name_arg(ls_tree_opts.get("full_name")))
|
|
180
|
+
sub_cmd_args.extend(self.full_tree_arg(ls_tree_opts.get("full_tree")))
|
|
181
|
+
|
|
182
|
+
sub_cmd_args.extend(self.abbrev_arg(ls_tree_opts.get("abbrev")))
|
|
183
|
+
sub_cmd_args.extend(self.format_arg(ls_tree_opts.get("format_")))
|
|
184
|
+
|
|
185
|
+
sub_cmd_args.extend(self.tree_ish_arg(tree_ish))
|
|
186
|
+
sub_cmd_args.extend(self.path_args(ls_tree_opts.get("path")))
|
|
187
|
+
|
|
188
|
+
return sub_cmd_args
|
|
189
|
+
|
|
190
|
+
def d_arg(self, d: bool | None) -> list[str]:
|
|
191
|
+
"""
|
|
192
|
+
Return ``-d`` if `d` is True.
|
|
193
|
+
|
|
194
|
+
:param d: Whether to include the ``-d`` option.
|
|
195
|
+
:return: List containing ``-d`` if applicable.
|
|
196
|
+
|
|
197
|
+
>>> IndividuallyOverridableLTCAB().d_arg(True)
|
|
198
|
+
['-d']
|
|
199
|
+
>>> IndividuallyOverridableLTCAB().d_arg(False)
|
|
200
|
+
[]
|
|
201
|
+
>>> IndividuallyOverridableLTCAB().d_arg(None)
|
|
202
|
+
[]
|
|
203
|
+
"""
|
|
204
|
+
return ["-d"] if d else []
|
|
205
|
+
|
|
206
|
+
def r_arg(self, r: bool | None) -> list[str]:
|
|
207
|
+
"""
|
|
208
|
+
Return ``-r`` if `r` is True.
|
|
209
|
+
|
|
210
|
+
:param r: Whether to include the ``-r`` option.
|
|
211
|
+
:return: List containing ``-r`` if applicable.
|
|
212
|
+
|
|
213
|
+
>>> IndividuallyOverridableLTCAB().r_arg(True)
|
|
214
|
+
['-r']
|
|
215
|
+
>>> IndividuallyOverridableLTCAB().r_arg(False)
|
|
216
|
+
[]
|
|
217
|
+
>>> IndividuallyOverridableLTCAB().r_arg(None)
|
|
218
|
+
[]
|
|
219
|
+
"""
|
|
220
|
+
return ["-r"] if r else []
|
|
221
|
+
|
|
222
|
+
def t_arg(self, t: bool | None) -> list[str]:
|
|
223
|
+
"""
|
|
224
|
+
Return ``-t`` if `t` is True.
|
|
225
|
+
|
|
226
|
+
:param t: Whether to include the ``-t`` option.
|
|
227
|
+
:return: List containing ``-t`` if applicable.
|
|
228
|
+
|
|
229
|
+
>>> IndividuallyOverridableLTCAB().t_arg(True)
|
|
230
|
+
['-t']
|
|
231
|
+
>>> IndividuallyOverridableLTCAB().t_arg(False)
|
|
232
|
+
[]
|
|
233
|
+
>>> IndividuallyOverridableLTCAB().t_arg(None)
|
|
234
|
+
[]
|
|
235
|
+
"""
|
|
236
|
+
return ["-t"] if t else []
|
|
237
|
+
|
|
238
|
+
def long_arg(self, long: bool | None) -> list[str]:
|
|
239
|
+
"""
|
|
240
|
+
Return ``-l`` if `long` is True.
|
|
241
|
+
|
|
242
|
+
:param long: Whether to include the ``-l`` option.
|
|
243
|
+
:return: List containing ``-l`` if applicable.
|
|
244
|
+
|
|
245
|
+
>>> IndividuallyOverridableLTCAB().long_arg(True)
|
|
246
|
+
['-l']
|
|
247
|
+
>>> IndividuallyOverridableLTCAB().long_arg(False)
|
|
248
|
+
[]
|
|
249
|
+
>>> IndividuallyOverridableLTCAB().long_arg(None)
|
|
250
|
+
[]
|
|
251
|
+
"""
|
|
252
|
+
return ["-l"] if long else []
|
|
253
|
+
|
|
254
|
+
def z_arg(self, z: bool | None) -> list[str]:
|
|
255
|
+
"""
|
|
256
|
+
Return ``-z`` if `z` is True.
|
|
257
|
+
|
|
258
|
+
:param z: Whether to include the ``-z`` option.
|
|
259
|
+
:return: List containing ``-z`` if applicable.
|
|
260
|
+
|
|
261
|
+
>>> IndividuallyOverridableLTCAB().z_arg(True)
|
|
262
|
+
['-z']
|
|
263
|
+
>>> IndividuallyOverridableLTCAB().z_arg(False)
|
|
264
|
+
[]
|
|
265
|
+
>>> IndividuallyOverridableLTCAB().z_arg(None)
|
|
266
|
+
[]
|
|
267
|
+
"""
|
|
268
|
+
return ["-z"] if z else []
|
|
269
|
+
|
|
270
|
+
def name_only_arg(self, name_only: bool | None) -> list[str]:
|
|
271
|
+
"""
|
|
272
|
+
Return ``--name-only`` if applicable.
|
|
273
|
+
|
|
274
|
+
>>> IndividuallyOverridableLTCAB().name_only_arg(True)
|
|
275
|
+
['--name-only']
|
|
276
|
+
>>> IndividuallyOverridableLTCAB().name_only_arg(False)
|
|
277
|
+
[]
|
|
278
|
+
>>> IndividuallyOverridableLTCAB().name_only_arg(None)
|
|
279
|
+
[]
|
|
280
|
+
"""
|
|
281
|
+
return ["--name-only"] if name_only else []
|
|
282
|
+
|
|
283
|
+
def name_status_arg(self, name_status: bool | None) -> list[str]:
|
|
284
|
+
"""
|
|
285
|
+
Return ``--name-status`` if applicable.
|
|
286
|
+
|
|
287
|
+
>>> IndividuallyOverridableLTCAB().name_status_arg(True)
|
|
288
|
+
['--name-status']
|
|
289
|
+
>>> IndividuallyOverridableLTCAB().name_status_arg(False)
|
|
290
|
+
[]
|
|
291
|
+
>>> IndividuallyOverridableLTCAB().name_status_arg(None)
|
|
292
|
+
[]
|
|
293
|
+
"""
|
|
294
|
+
return ["--name-status"] if name_status else []
|
|
295
|
+
|
|
296
|
+
def object_only_arg(self, object_only: bool | None) -> list[str]:
|
|
297
|
+
"""
|
|
298
|
+
Return ``--object-only`` if applicable.
|
|
299
|
+
|
|
300
|
+
>>> IndividuallyOverridableLTCAB().object_only_arg(True)
|
|
301
|
+
['--object-only']
|
|
302
|
+
>>> IndividuallyOverridableLTCAB().object_only_arg(False)
|
|
303
|
+
[]
|
|
304
|
+
>>> IndividuallyOverridableLTCAB().object_only_arg(None)
|
|
305
|
+
[]
|
|
306
|
+
"""
|
|
307
|
+
return ["--object-only"] if object_only else []
|
|
308
|
+
|
|
309
|
+
def full_name_arg(self, full_name: bool | None) -> list[str]:
|
|
310
|
+
"""
|
|
311
|
+
Return ``--full-name`` if applicable.
|
|
312
|
+
|
|
313
|
+
>>> IndividuallyOverridableLTCAB().full_name_arg(True)
|
|
314
|
+
['--full-name']
|
|
315
|
+
>>> IndividuallyOverridableLTCAB().full_name_arg(False)
|
|
316
|
+
[]
|
|
317
|
+
>>> IndividuallyOverridableLTCAB().full_name_arg(None)
|
|
318
|
+
[]
|
|
319
|
+
"""
|
|
320
|
+
return ["--full-name"] if full_name else []
|
|
321
|
+
|
|
322
|
+
def full_tree_arg(self, full_tree: bool | None) -> list[str]:
|
|
323
|
+
"""
|
|
324
|
+
Return ``--full-tree`` if applicable.
|
|
325
|
+
|
|
326
|
+
>>> IndividuallyOverridableLTCAB().full_tree_arg(True)
|
|
327
|
+
['--full-tree']
|
|
328
|
+
>>> IndividuallyOverridableLTCAB().full_tree_arg(False)
|
|
329
|
+
[]
|
|
330
|
+
>>> IndividuallyOverridableLTCAB().full_tree_arg(None)
|
|
331
|
+
[]
|
|
332
|
+
"""
|
|
333
|
+
return ["--full-tree"] if full_tree else []
|
|
334
|
+
|
|
335
|
+
def abbrev_arg(self, abbrev: int | None) -> list[str]:
|
|
336
|
+
"""
|
|
337
|
+
Format ``--abbrev=N`` if `abbrev` is provided.
|
|
338
|
+
|
|
339
|
+
:param abbrev: Abbreviation length (0-40 inclusive).
|
|
340
|
+
:return: List containing formatted option or empty list.
|
|
341
|
+
|
|
342
|
+
>>> IndividuallyOverridableLTCAB().abbrev_arg(None)
|
|
343
|
+
[]
|
|
344
|
+
>>> IndividuallyOverridableLTCAB().abbrev_arg(7)
|
|
345
|
+
['--abbrev=7']
|
|
346
|
+
>>> IndividuallyOverridableLTCAB().abbrev_arg(0)
|
|
347
|
+
['--abbrev=0']
|
|
348
|
+
>>> IndividuallyOverridableLTCAB().abbrev_arg(40)
|
|
349
|
+
['--abbrev=40']
|
|
350
|
+
"""
|
|
351
|
+
return [f"--abbrev={abbrev}"] if abbrev is not None else []
|
|
352
|
+
|
|
353
|
+
def format_arg(self, _format: str | None) -> list[str]:
|
|
354
|
+
"""
|
|
355
|
+
Format ``--format=...`` if `_format` is provided.
|
|
356
|
+
|
|
357
|
+
:param _format: A valid format string.
|
|
358
|
+
:return: List containing formatted option or empty list.
|
|
359
|
+
|
|
360
|
+
>>> IndividuallyOverridableLTCAB().format_arg(None)
|
|
361
|
+
[]
|
|
362
|
+
>>> IndividuallyOverridableLTCAB().format_arg('%(objectname)')
|
|
363
|
+
['--format', '%(objectname)']
|
|
364
|
+
>>> IndividuallyOverridableLTCAB().format_arg('""')
|
|
365
|
+
['--format', '""']
|
|
366
|
+
>>> IndividuallyOverridableLTCAB().format_arg("''")
|
|
367
|
+
['--format', "''"]
|
|
368
|
+
>>> IndividuallyOverridableLTCAB().format_arg('%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)')
|
|
369
|
+
['--format', '%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)']
|
|
370
|
+
>>> IndividuallyOverridableLTCAB().format_arg('"%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)"')
|
|
371
|
+
['--format', '"%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)"']
|
|
372
|
+
"""
|
|
373
|
+
return ["--format", _format] if _format is not None else []
|
|
374
|
+
|
|
375
|
+
def tree_ish_arg(self, tree_ish: str) -> list[str]:
|
|
376
|
+
"""
|
|
377
|
+
Return the required tree-ish identifier as a single-element list.
|
|
378
|
+
|
|
379
|
+
This value is typically a commit SHA, branch name, tag, or other valid tree reference
|
|
380
|
+
and is appended at the end of the formed git subcommand options, just before path(s).
|
|
381
|
+
|
|
382
|
+
>>> IndividuallyOverridableLTCAB().tree_ish_arg("HEAD")
|
|
383
|
+
['HEAD']
|
|
384
|
+
>>> IndividuallyOverridableLTCAB().tree_ish_arg("origin/main")
|
|
385
|
+
['origin/main']
|
|
386
|
+
>>> IndividuallyOverridableLTCAB().tree_ish_arg("a1b2c3d")
|
|
387
|
+
['a1b2c3d']
|
|
388
|
+
>>> IndividuallyOverridableLTCAB().tree_ish_arg("")
|
|
389
|
+
['']
|
|
390
|
+
"""
|
|
391
|
+
return [tree_ish]
|
|
392
|
+
|
|
393
|
+
def path_args(self, path: list[str] | None) -> list[str]:
|
|
394
|
+
"""
|
|
395
|
+
Return the list of paths (if any) passed to ``git ls-tree``.
|
|
396
|
+
|
|
397
|
+
If `path` is None or an empty list, this returns an empty list.
|
|
398
|
+
|
|
399
|
+
>>> IndividuallyOverridableLTCAB().path_args(["src", "README.md"])
|
|
400
|
+
['src', 'README.md']
|
|
401
|
+
>>> IndividuallyOverridableLTCAB().path_args([])
|
|
402
|
+
[]
|
|
403
|
+
>>> IndividuallyOverridableLTCAB().path_args(None)
|
|
404
|
+
[]
|
|
405
|
+
"""
|
|
406
|
+
return path if path else []
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Git command runner interfaces to run subprocess calls.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import pathlib
|
|
11
|
+
from abc import abstractmethod
|
|
12
|
+
from subprocess import CompletedProcess, Popen
|
|
13
|
+
from typing import Protocol, overload, Any, Literal
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class GitCommandRunner(Protocol):
|
|
17
|
+
"""
|
|
18
|
+
Interface to facilitate running git commands in subprocess.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
@overload
|
|
22
|
+
@abstractmethod
|
|
23
|
+
def run_git_command(
|
|
24
|
+
self,
|
|
25
|
+
main_cmd_args: list[str],
|
|
26
|
+
subcommand_args: list[str],
|
|
27
|
+
*subprocess_run_args: Any,
|
|
28
|
+
_input: str,
|
|
29
|
+
text: Literal[True],
|
|
30
|
+
**subprocess_run_kwargs: Any,
|
|
31
|
+
) -> CompletedProcess[str]: ...
|
|
32
|
+
|
|
33
|
+
@overload
|
|
34
|
+
@abstractmethod
|
|
35
|
+
def run_git_command(
|
|
36
|
+
self,
|
|
37
|
+
main_cmd_args: list[str],
|
|
38
|
+
subcommand_args: list[str],
|
|
39
|
+
*subprocess_run_args: Any,
|
|
40
|
+
_input: bytes,
|
|
41
|
+
text: Literal[False],
|
|
42
|
+
**subprocess_run_kwargs: Any,
|
|
43
|
+
) -> CompletedProcess[bytes]: ...
|
|
44
|
+
|
|
45
|
+
@overload
|
|
46
|
+
@abstractmethod
|
|
47
|
+
def run_git_command(
|
|
48
|
+
self,
|
|
49
|
+
main_cmd_args: list[str],
|
|
50
|
+
subcommand_args: list[str],
|
|
51
|
+
*subprocess_run_args: Any,
|
|
52
|
+
text: Literal[True],
|
|
53
|
+
**subprocess_run_kwargs: Any,
|
|
54
|
+
) -> CompletedProcess[str]: ...
|
|
55
|
+
|
|
56
|
+
@overload
|
|
57
|
+
@abstractmethod
|
|
58
|
+
def run_git_command(
|
|
59
|
+
self,
|
|
60
|
+
main_cmd_args: list[str],
|
|
61
|
+
subcommand_args: list[str],
|
|
62
|
+
*subprocess_run_args: Any,
|
|
63
|
+
text: Literal[False] = ...,
|
|
64
|
+
**subprocess_run_kwargs: Any,
|
|
65
|
+
) -> CompletedProcess[bytes]: ...
|
|
66
|
+
|
|
67
|
+
@overload
|
|
68
|
+
@abstractmethod
|
|
69
|
+
def popen_git_command(
|
|
70
|
+
self,
|
|
71
|
+
main_cmd_args: list[str],
|
|
72
|
+
subcommand_args: list[str],
|
|
73
|
+
*popen_run_args: Any,
|
|
74
|
+
text: Literal[False],
|
|
75
|
+
**popen_run_kwargs: Any,
|
|
76
|
+
) -> Popen[bytes]: ...
|
|
77
|
+
|
|
78
|
+
@overload
|
|
79
|
+
@abstractmethod
|
|
80
|
+
def popen_git_command(
|
|
81
|
+
self,
|
|
82
|
+
main_cmd_args: list[str],
|
|
83
|
+
subcommand_args: list[str],
|
|
84
|
+
*popen_run_args: Any,
|
|
85
|
+
text: Literal[True],
|
|
86
|
+
**popen_run_kwargs: Any,
|
|
87
|
+
) -> Popen[str]: ...
|
|
88
|
+
|
|
89
|
+
@abstractmethod
|
|
90
|
+
def make_cmd(self, main_cmd_args: list[str], sub_cmd_args: list[str]) -> list[str]:
|
|
91
|
+
"""
|
|
92
|
+
Make command for execution for use in an external subprocess.
|
|
93
|
+
|
|
94
|
+
:param main_cmd_args: arguments for the main command.
|
|
95
|
+
:param sub_cmd_args: arguments for subcommand.
|
|
96
|
+
:returns: a fully made and runnable command for some external ``subprocess`` call.
|
|
97
|
+
"""
|
|
98
|
+
...
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
@abstractmethod
|
|
102
|
+
def git_prog(self) -> str | pathlib.Path:
|
|
103
|
+
"""
|
|
104
|
+
:returns: git path location or git program name.
|
|
105
|
+
"""
|
|
106
|
+
...
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
A simple and straight-forward git command subprocess runner implementation.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import pathlib
|
|
11
|
+
import subprocess
|
|
12
|
+
from subprocess import CompletedProcess, Popen
|
|
13
|
+
from typing import overload, override, Any, Literal
|
|
14
|
+
|
|
15
|
+
from gitbolt.subprocess.constants import GIT_CMD
|
|
16
|
+
from gitbolt.subprocess.exceptions import GitCmdException
|
|
17
|
+
from gitbolt.subprocess.runner import GitCommandRunner
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SimpleGitCR(GitCommandRunner):
|
|
21
|
+
"""
|
|
22
|
+
Simple git command runner that simply runs everything `as-is` in a subprocess.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def __init__(self, git_prog: str | pathlib.Path = GIT_CMD):
|
|
26
|
+
"""
|
|
27
|
+
:param git_prog: git program name/location. Useful when user wants to run a separate git version/git emulator.
|
|
28
|
+
"""
|
|
29
|
+
self._git_prog = git_prog
|
|
30
|
+
|
|
31
|
+
@overload
|
|
32
|
+
@override
|
|
33
|
+
def run_git_command(
|
|
34
|
+
self,
|
|
35
|
+
main_cmd_args: list[str],
|
|
36
|
+
subcommand_args: list[str],
|
|
37
|
+
*subprocess_run_args: Any,
|
|
38
|
+
_input: str,
|
|
39
|
+
text: Literal[True],
|
|
40
|
+
**subprocess_run_kwargs: Any,
|
|
41
|
+
) -> CompletedProcess[str]: ...
|
|
42
|
+
|
|
43
|
+
@overload
|
|
44
|
+
@override
|
|
45
|
+
def run_git_command(
|
|
46
|
+
self,
|
|
47
|
+
main_cmd_args: list[str],
|
|
48
|
+
subcommand_args: list[str],
|
|
49
|
+
*subprocess_run_args: Any,
|
|
50
|
+
_input: bytes,
|
|
51
|
+
text: Literal[False],
|
|
52
|
+
**subprocess_run_kwargs: Any,
|
|
53
|
+
) -> CompletedProcess[bytes]: ...
|
|
54
|
+
|
|
55
|
+
@overload
|
|
56
|
+
@override
|
|
57
|
+
def run_git_command(
|
|
58
|
+
self,
|
|
59
|
+
main_cmd_args: list[str],
|
|
60
|
+
subcommand_args: list[str],
|
|
61
|
+
*subprocess_run_args: Any,
|
|
62
|
+
text: Literal[True],
|
|
63
|
+
**subprocess_run_kwargs: Any,
|
|
64
|
+
) -> CompletedProcess[str]: ...
|
|
65
|
+
|
|
66
|
+
@overload
|
|
67
|
+
@override
|
|
68
|
+
def run_git_command(
|
|
69
|
+
self,
|
|
70
|
+
main_cmd_args: list[str],
|
|
71
|
+
subcommand_args: list[str],
|
|
72
|
+
*subprocess_run_args: Any,
|
|
73
|
+
text: Literal[False] = ...,
|
|
74
|
+
**subprocess_run_kwargs: Any,
|
|
75
|
+
) -> CompletedProcess[bytes]: ...
|
|
76
|
+
|
|
77
|
+
@override
|
|
78
|
+
def run_git_command(
|
|
79
|
+
self,
|
|
80
|
+
main_cmd_args: list[str],
|
|
81
|
+
subcommand_args: list[str],
|
|
82
|
+
*subprocess_run_args: Any,
|
|
83
|
+
_input: str | bytes | None = None,
|
|
84
|
+
text: Literal[True, False] = False,
|
|
85
|
+
**subprocess_run_kwargs: Any,
|
|
86
|
+
) -> CompletedProcess[str] | CompletedProcess[bytes]:
|
|
87
|
+
try:
|
|
88
|
+
return subprocess.run(
|
|
89
|
+
self.make_cmd(main_cmd_args, subcommand_args),
|
|
90
|
+
*subprocess_run_args,
|
|
91
|
+
input=_input,
|
|
92
|
+
text=text,
|
|
93
|
+
**subprocess_run_kwargs,
|
|
94
|
+
)
|
|
95
|
+
except subprocess.CalledProcessError as e:
|
|
96
|
+
raise GitCmdException(
|
|
97
|
+
e.stderr, called_process_error=e, exit_code=e.returncode
|
|
98
|
+
) from e
|
|
99
|
+
|
|
100
|
+
@overload
|
|
101
|
+
@override
|
|
102
|
+
def popen_git_command(
|
|
103
|
+
self,
|
|
104
|
+
main_cmd_args: list[str],
|
|
105
|
+
subcommand_args: list[str],
|
|
106
|
+
*popen_run_args: Any,
|
|
107
|
+
text: Literal[False],
|
|
108
|
+
**popen_run_kwargs: Any,
|
|
109
|
+
) -> Popen[bytes]: ...
|
|
110
|
+
|
|
111
|
+
@overload
|
|
112
|
+
@override
|
|
113
|
+
def popen_git_command(
|
|
114
|
+
self,
|
|
115
|
+
main_cmd_args: list[str],
|
|
116
|
+
subcommand_args: list[str],
|
|
117
|
+
*popen_run_args: Any,
|
|
118
|
+
text: Literal[True],
|
|
119
|
+
**popen_run_kwargs: Any,
|
|
120
|
+
) -> Popen[str]: ...
|
|
121
|
+
|
|
122
|
+
@override
|
|
123
|
+
def popen_git_command(
|
|
124
|
+
self,
|
|
125
|
+
main_cmd_args: list[str],
|
|
126
|
+
subcommand_args: list[str],
|
|
127
|
+
*popen_run_args: Any,
|
|
128
|
+
text: Literal[True, False],
|
|
129
|
+
**popen_run_kwargs: Any,
|
|
130
|
+
) -> Popen[str] | Popen[bytes]:
|
|
131
|
+
try:
|
|
132
|
+
return subprocess.Popen(
|
|
133
|
+
self.make_cmd(main_cmd_args, subcommand_args),
|
|
134
|
+
*popen_run_args,
|
|
135
|
+
text=text,
|
|
136
|
+
**popen_run_kwargs,
|
|
137
|
+
)
|
|
138
|
+
except subprocess.CalledProcessError as e:
|
|
139
|
+
raise GitCmdException(
|
|
140
|
+
e.stderr, called_process_error=e, exit_code=e.returncode
|
|
141
|
+
) from e
|
|
142
|
+
|
|
143
|
+
@override
|
|
144
|
+
def make_cmd(self, main_cmd_args: list[str], sub_cmd_args: list[str]) -> list[str]:
|
|
145
|
+
return [str(self.git_prog), *main_cmd_args, *sub_cmd_args]
|
|
146
|
+
|
|
147
|
+
@override
|
|
148
|
+
@property
|
|
149
|
+
def git_prog(self) -> str | pathlib.Path:
|
|
150
|
+
return self._git_prog
|