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
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Helper interfaces for ``git add`` subcommand with default implementation for subprocess calls.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from abc import abstractmethod
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Protocol, Unpack, override, Literal
|
|
11
|
+
|
|
12
|
+
from gitbolt.git_subprocess.constants import ADD_CMD
|
|
13
|
+
from gitbolt.models import GitAddOpts
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class AddCLIArgsBuilder(Protocol):
|
|
17
|
+
"""
|
|
18
|
+
Interface to facilitate building of cli arguments for ``git add`` subcommand.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
@abstractmethod
|
|
22
|
+
def build(
|
|
23
|
+
self,
|
|
24
|
+
pathspec: str | None = None,
|
|
25
|
+
*pathspecs: str,
|
|
26
|
+
pathspec_from_file: Path | Literal["-"] | None = None,
|
|
27
|
+
pathspec_file_nul: bool = False,
|
|
28
|
+
**add_opts: Unpack[GitAddOpts],
|
|
29
|
+
) -> list[str]:
|
|
30
|
+
"""
|
|
31
|
+
Build the complete list of subcommand arguments to be passed to ``git add``.
|
|
32
|
+
|
|
33
|
+
This method assembles the subcommand portion of the git command invocation, such as
|
|
34
|
+
in ``git --no-pager add --ignore-missing add-file.py``, where ``--ignore-missing add-file.py`` is the
|
|
35
|
+
subcommand argument list.
|
|
36
|
+
|
|
37
|
+
It delegates the formation of each argument to protected helper methods to allow
|
|
38
|
+
easier overriding and testing of individual components.
|
|
39
|
+
|
|
40
|
+
Includes support for:
|
|
41
|
+
|
|
42
|
+
- Boolean flags (e.g., --verbose, --dry-run, etc)
|
|
43
|
+
- Optional key-value arguments (e.g., --chmod=+x)
|
|
44
|
+
- Optional pathspecs
|
|
45
|
+
- Optional pathspec-from-file
|
|
46
|
+
|
|
47
|
+
See: `git add documentation <https://git-scm.com/docs/git-add>`_.
|
|
48
|
+
|
|
49
|
+
:param pathspec: A direct file or directory to stage. Cannot be used with ``pathspec_from_file``.
|
|
50
|
+
:type pathspec: str | None
|
|
51
|
+
:param pathspecs: Additional pathspecs to stage.
|
|
52
|
+
:type pathspecs: str
|
|
53
|
+
:param pathspec_from_file: A file to read pathspecs from. Use ``'-'`` to read from stdin.
|
|
54
|
+
:type pathspec_from_file: Path | Literal['-'] | None
|
|
55
|
+
:param pathspec_stdin: Required if ``pathspec_from_file == '-'``. Denotes stdin content.
|
|
56
|
+
:type pathspec_stdin: str | None
|
|
57
|
+
:param pathspec_file_nul: Whether input lines in ``pathspec_from_file`` are NUL-separated.
|
|
58
|
+
:type pathspec_file_nul: bool
|
|
59
|
+
:param add_opts: Options accepted by the ``git add`` subcommand.
|
|
60
|
+
:type add_opts: Unpack[GitAddOpts]
|
|
61
|
+
:return: Complete list of subcommand arguments.
|
|
62
|
+
:raises GitExitingException: if undesired argument type or argument combination is supplied.
|
|
63
|
+
"""
|
|
64
|
+
...
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class IndividuallyOverridableACAB(AddCLIArgsBuilder):
|
|
68
|
+
"""
|
|
69
|
+
Individually Overridable Add CLI Args Builder.
|
|
70
|
+
|
|
71
|
+
Build CLI args to run ``git add`` subcommand in a subprocess. This class is independent in its working and
|
|
72
|
+
provides interface to individually override each arg former for fine-grained control.
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
@override
|
|
76
|
+
def build(
|
|
77
|
+
self,
|
|
78
|
+
pathspec: str | None = None,
|
|
79
|
+
*pathspecs: str,
|
|
80
|
+
pathspec_from_file: Path | Literal["-"] | None = None,
|
|
81
|
+
pathspec_file_nul: bool = False,
|
|
82
|
+
**add_opts: Unpack[GitAddOpts],
|
|
83
|
+
) -> list[str]:
|
|
84
|
+
"""
|
|
85
|
+
Build the full list of arguments to be passed to ``git add``.
|
|
86
|
+
|
|
87
|
+
This includes flags, optional arguments, pathspec identifier, and optional pathspecs etc.
|
|
88
|
+
|
|
89
|
+
>>> builder = IndividuallyOverridableACAB()
|
|
90
|
+
|
|
91
|
+
Example usage and expected results:
|
|
92
|
+
|
|
93
|
+
>>> builder = IndividuallyOverridableACAB()
|
|
94
|
+
|
|
95
|
+
Basic usage with one pathspec:
|
|
96
|
+
|
|
97
|
+
>>> builder.build("file.txt")
|
|
98
|
+
['add', 'file.txt']
|
|
99
|
+
|
|
100
|
+
Using boolean flags:
|
|
101
|
+
|
|
102
|
+
>>> builder.build("file.txt", verbose=True, dry_run=True)
|
|
103
|
+
['add', '--verbose', '--dry-run', 'file.txt']
|
|
104
|
+
|
|
105
|
+
Using tri-state options:
|
|
106
|
+
|
|
107
|
+
>>> builder.build("file.txt", no_all=True, no_ignore_removal=False)
|
|
108
|
+
['add', '--no-all', '--ignore-removal', 'file.txt']
|
|
109
|
+
|
|
110
|
+
Using optional value flag:
|
|
111
|
+
|
|
112
|
+
>>> builder.build("file.txt", chmod='+x')
|
|
113
|
+
['add', '--chmod=+x', 'file.txt']
|
|
114
|
+
|
|
115
|
+
Using multiple pathspecs:
|
|
116
|
+
|
|
117
|
+
>>> builder.build("src", "tests", verbose=True)
|
|
118
|
+
['add', '--verbose', 'src', 'tests']
|
|
119
|
+
|
|
120
|
+
With pathspec_from_file (as a file path):
|
|
121
|
+
|
|
122
|
+
>>> builder.build(pathspec_from_file=Path("specs.txt"))
|
|
123
|
+
['add', '--pathspec-from-file=specs.txt']
|
|
124
|
+
|
|
125
|
+
With pathspec_from_file from stdin:
|
|
126
|
+
|
|
127
|
+
>>> builder.build(pathspec_from_file='-')
|
|
128
|
+
['add', '--pathspec-from-file=-']
|
|
129
|
+
|
|
130
|
+
With pathspec_file_nul flag:
|
|
131
|
+
|
|
132
|
+
>>> builder.build(pathspec_file_nul=True)
|
|
133
|
+
['add', '--pathspec-file-nul']
|
|
134
|
+
|
|
135
|
+
All applicable flags and values:
|
|
136
|
+
|
|
137
|
+
>>> builder.build("src/file.py", verbose=True, dry_run=True, force=True, interactive=True,
|
|
138
|
+
... patch=True, edit=True, no_all=False, no_ignore_removal=True, sparse=True,
|
|
139
|
+
... intent_to_add=True, refresh=True, ignore_errors=True, ignore_missing=True,
|
|
140
|
+
... renormalize=True, chmod='-x')
|
|
141
|
+
['add', '--verbose', '--dry-run', '--force', '--interactive', '--patch', '--edit', '--all', '--no-ignore-removal', '--sparse', '--intent-to-add', '--refresh', '--ignore-errors', '--ignore-missing', '--renormalize', '--chmod=-x', 'src/file.py']
|
|
142
|
+
"""
|
|
143
|
+
sub_cmd_args = [ADD_CMD]
|
|
144
|
+
|
|
145
|
+
# region GitAddOpts members
|
|
146
|
+
# region bool flags
|
|
147
|
+
sub_cmd_args.extend(self.verbose_arg(add_opts.get("verbose")))
|
|
148
|
+
sub_cmd_args.extend(self.dry_run_arg(add_opts.get("dry_run")))
|
|
149
|
+
sub_cmd_args.extend(self.force_arg(add_opts.get("force")))
|
|
150
|
+
sub_cmd_args.extend(self.interactive_arg(add_opts.get("interactive")))
|
|
151
|
+
sub_cmd_args.extend(self.patch_arg(add_opts.get("patch")))
|
|
152
|
+
sub_cmd_args.extend(self.edit_arg(add_opts.get("edit")))
|
|
153
|
+
|
|
154
|
+
# region tri-state flags
|
|
155
|
+
sub_cmd_args.extend(self.no_all(add_opts.get("no_all")))
|
|
156
|
+
sub_cmd_args.extend(
|
|
157
|
+
self.no_ignore_removal_arg(add_opts.get("no_ignore_removal"))
|
|
158
|
+
)
|
|
159
|
+
# endregion
|
|
160
|
+
|
|
161
|
+
sub_cmd_args.extend(self.sparse_arg(add_opts.get("sparse")))
|
|
162
|
+
sub_cmd_args.extend(self.intent_to_add_arg(add_opts.get("intent_to_add")))
|
|
163
|
+
|
|
164
|
+
sub_cmd_args.extend(self.refresh_arg(add_opts.get("refresh")))
|
|
165
|
+
sub_cmd_args.extend(self.ignore_errors_arg(add_opts.get("ignore_errors")))
|
|
166
|
+
sub_cmd_args.extend(self.ignore_missing_arg(add_opts.get("ignore_missing")))
|
|
167
|
+
sub_cmd_args.extend(self.renormalize_arg(add_opts.get("renormalize")))
|
|
168
|
+
# endregion
|
|
169
|
+
|
|
170
|
+
sub_cmd_args.extend(self.chmod_arg(add_opts.get("chmod")))
|
|
171
|
+
# endregion
|
|
172
|
+
|
|
173
|
+
# region non GitOpts members
|
|
174
|
+
sub_cmd_args.extend(self.pathspec_file_nul_arg(pathspec_file_nul))
|
|
175
|
+
sub_cmd_args.extend(self.pathspec_from_file_arg(pathspec_from_file))
|
|
176
|
+
sub_cmd_args.extend(self.pathspec_arg(pathspec, *pathspecs))
|
|
177
|
+
# endregion
|
|
178
|
+
|
|
179
|
+
return sub_cmd_args
|
|
180
|
+
|
|
181
|
+
def verbose_arg(self, verbose: bool | None) -> list[str]:
|
|
182
|
+
"""
|
|
183
|
+
Return ``--verbose`` if `verbose` is True.
|
|
184
|
+
|
|
185
|
+
:param verbose: Whether to include the ``--verbose`` option.
|
|
186
|
+
:return: List containing ``--verbose`` if applicable.
|
|
187
|
+
|
|
188
|
+
>>> IndividuallyOverridableACAB().verbose_arg(True)
|
|
189
|
+
['--verbose']
|
|
190
|
+
>>> IndividuallyOverridableACAB().verbose_arg(False)
|
|
191
|
+
[]
|
|
192
|
+
>>> IndividuallyOverridableACAB().verbose_arg(None)
|
|
193
|
+
[]
|
|
194
|
+
"""
|
|
195
|
+
return ["--verbose"] if verbose else []
|
|
196
|
+
|
|
197
|
+
def dry_run_arg(self, dry_run: bool | None) -> list[str]:
|
|
198
|
+
"""
|
|
199
|
+
Return ``--dry-run`` if `dry_run` is True.
|
|
200
|
+
|
|
201
|
+
:param dry_run: Whether to include the ``--dry-run`` option.
|
|
202
|
+
:return: List containing ``--dry-run`` if applicable.
|
|
203
|
+
|
|
204
|
+
>>> IndividuallyOverridableACAB().dry_run_arg(True)
|
|
205
|
+
['--dry-run']
|
|
206
|
+
>>> IndividuallyOverridableACAB().dry_run_arg(False)
|
|
207
|
+
[]
|
|
208
|
+
>>> IndividuallyOverridableACAB().dry_run_arg(None)
|
|
209
|
+
[]
|
|
210
|
+
"""
|
|
211
|
+
return ["--dry-run"] if dry_run else []
|
|
212
|
+
|
|
213
|
+
def force_arg(self, force: bool | None) -> list[str]:
|
|
214
|
+
"""
|
|
215
|
+
Return ``--force`` if `force` is True.
|
|
216
|
+
|
|
217
|
+
:param force: Whether to include the ``--force`` option.
|
|
218
|
+
:return: List containing ``--force`` if applicable.
|
|
219
|
+
|
|
220
|
+
>>> IndividuallyOverridableACAB().force_arg(True)
|
|
221
|
+
['--force']
|
|
222
|
+
>>> IndividuallyOverridableACAB().force_arg(False)
|
|
223
|
+
[]
|
|
224
|
+
>>> IndividuallyOverridableACAB().force_arg(None)
|
|
225
|
+
[]
|
|
226
|
+
"""
|
|
227
|
+
return ["--force"] if force else []
|
|
228
|
+
|
|
229
|
+
def interactive_arg(self, interactive: bool | None) -> list[str]:
|
|
230
|
+
"""
|
|
231
|
+
Return ``--interactive`` if `interactive` is True.
|
|
232
|
+
|
|
233
|
+
:param interactive: Whether to include the ``--interactive`` option.
|
|
234
|
+
:return: List containing ``--interactive`` if applicable.
|
|
235
|
+
|
|
236
|
+
>>> IndividuallyOverridableACAB().interactive_arg(True)
|
|
237
|
+
['--interactive']
|
|
238
|
+
>>> IndividuallyOverridableACAB().interactive_arg(False)
|
|
239
|
+
[]
|
|
240
|
+
>>> IndividuallyOverridableACAB().interactive_arg(None)
|
|
241
|
+
[]
|
|
242
|
+
"""
|
|
243
|
+
return ["--interactive"] if interactive else []
|
|
244
|
+
|
|
245
|
+
def patch_arg(self, patch: bool | None) -> list[str]:
|
|
246
|
+
"""
|
|
247
|
+
Return ``--patch`` if `patch` is True.
|
|
248
|
+
|
|
249
|
+
:param patch: Whether to include the ``--patch`` option.
|
|
250
|
+
:return: List containing ``--patch`` if applicable.
|
|
251
|
+
|
|
252
|
+
>>> IndividuallyOverridableACAB().patch_arg(True)
|
|
253
|
+
['--patch']
|
|
254
|
+
>>> IndividuallyOverridableACAB().patch_arg(False)
|
|
255
|
+
[]
|
|
256
|
+
>>> IndividuallyOverridableACAB().patch_arg(None)
|
|
257
|
+
[]
|
|
258
|
+
"""
|
|
259
|
+
return ["--patch"] if patch else []
|
|
260
|
+
|
|
261
|
+
def edit_arg(self, edit: bool | None) -> list[str]:
|
|
262
|
+
"""
|
|
263
|
+
Return ``--edit`` if applicable.
|
|
264
|
+
|
|
265
|
+
>>> IndividuallyOverridableACAB().edit_arg(True)
|
|
266
|
+
['--edit']
|
|
267
|
+
>>> IndividuallyOverridableACAB().edit_arg(False)
|
|
268
|
+
[]
|
|
269
|
+
>>> IndividuallyOverridableACAB().edit_arg(None)
|
|
270
|
+
[]
|
|
271
|
+
"""
|
|
272
|
+
return ["--edit"] if edit else []
|
|
273
|
+
|
|
274
|
+
def no_all(self, no_all: bool | None) -> list[str]:
|
|
275
|
+
"""
|
|
276
|
+
Return ``--no-all`` or ``--all`` if applicable.
|
|
277
|
+
|
|
278
|
+
>>> IndividuallyOverridableACAB().no_all(True)
|
|
279
|
+
['--no-all']
|
|
280
|
+
>>> IndividuallyOverridableACAB().no_all(False)
|
|
281
|
+
['--all']
|
|
282
|
+
>>> IndividuallyOverridableACAB().no_all(None)
|
|
283
|
+
[]
|
|
284
|
+
"""
|
|
285
|
+
if no_all is None:
|
|
286
|
+
return []
|
|
287
|
+
return ["--no-all"] if no_all else ["--all"]
|
|
288
|
+
|
|
289
|
+
def no_ignore_removal_arg(self, no_ignore_removal: bool | None) -> list[str]:
|
|
290
|
+
"""
|
|
291
|
+
Return ``--no-ignore-removal`` or ``--ignore-removal`` if applicable.
|
|
292
|
+
|
|
293
|
+
>>> IndividuallyOverridableACAB().no_ignore_removal_arg(True)
|
|
294
|
+
['--no-ignore-removal']
|
|
295
|
+
>>> IndividuallyOverridableACAB().no_ignore_removal_arg(False)
|
|
296
|
+
['--ignore-removal']
|
|
297
|
+
>>> IndividuallyOverridableACAB().no_ignore_removal_arg(None)
|
|
298
|
+
[]
|
|
299
|
+
"""
|
|
300
|
+
if no_ignore_removal is None:
|
|
301
|
+
return []
|
|
302
|
+
return ["--no-ignore-removal"] if no_ignore_removal else ["--ignore-removal"]
|
|
303
|
+
|
|
304
|
+
def sparse_arg(self, sparse: bool | None) -> list[str]:
|
|
305
|
+
"""
|
|
306
|
+
Return ``--sparse`` if applicable.
|
|
307
|
+
|
|
308
|
+
>>> IndividuallyOverridableACAB().sparse_arg(True)
|
|
309
|
+
['--sparse']
|
|
310
|
+
>>> IndividuallyOverridableACAB().sparse_arg(False)
|
|
311
|
+
[]
|
|
312
|
+
>>> IndividuallyOverridableACAB().sparse_arg(None)
|
|
313
|
+
[]
|
|
314
|
+
"""
|
|
315
|
+
return ["--sparse"] if sparse else []
|
|
316
|
+
|
|
317
|
+
def intent_to_add_arg(self, intent_to_add: bool | None) -> list[str]:
|
|
318
|
+
"""
|
|
319
|
+
Return ``--intent-to-add`` if applicable.
|
|
320
|
+
|
|
321
|
+
>>> IndividuallyOverridableACAB().intent_to_add_arg(True)
|
|
322
|
+
['--intent-to-add']
|
|
323
|
+
>>> IndividuallyOverridableACAB().intent_to_add_arg(False)
|
|
324
|
+
[]
|
|
325
|
+
>>> IndividuallyOverridableACAB().intent_to_add_arg(None)
|
|
326
|
+
[]
|
|
327
|
+
"""
|
|
328
|
+
return ["--intent-to-add"] if intent_to_add else []
|
|
329
|
+
|
|
330
|
+
def refresh_arg(self, refresh: bool | None) -> list[str]:
|
|
331
|
+
"""
|
|
332
|
+
Returns ``--refresh`` if applicable.
|
|
333
|
+
|
|
334
|
+
>>> IndividuallyOverridableACAB().refresh_arg(None)
|
|
335
|
+
[]
|
|
336
|
+
>>> IndividuallyOverridableACAB().refresh_arg(True)
|
|
337
|
+
['--refresh']
|
|
338
|
+
>>> IndividuallyOverridableACAB().refresh_arg(False)
|
|
339
|
+
[]
|
|
340
|
+
"""
|
|
341
|
+
return ["--refresh"] if refresh else []
|
|
342
|
+
|
|
343
|
+
def ignore_errors_arg(self, ignore_errors: bool | None) -> list[str]:
|
|
344
|
+
"""
|
|
345
|
+
Returns ``--ignore-errors`` if applicable.
|
|
346
|
+
|
|
347
|
+
>>> IndividuallyOverridableACAB().ignore_errors_arg(True)
|
|
348
|
+
['--ignore-errors']
|
|
349
|
+
>>> IndividuallyOverridableACAB().ignore_errors_arg(None)
|
|
350
|
+
[]
|
|
351
|
+
>>> IndividuallyOverridableACAB().ignore_errors_arg(False)
|
|
352
|
+
[]
|
|
353
|
+
"""
|
|
354
|
+
return ["--ignore-errors"] if ignore_errors else []
|
|
355
|
+
|
|
356
|
+
def ignore_missing_arg(self, ignore_missing: bool | None) -> list[str]:
|
|
357
|
+
"""
|
|
358
|
+
Returns ``--ignore-missing`` if applicable.
|
|
359
|
+
|
|
360
|
+
>>> IndividuallyOverridableACAB().ignore_missing_arg(True)
|
|
361
|
+
['--ignore-missing']
|
|
362
|
+
>>> IndividuallyOverridableACAB().ignore_missing_arg(None)
|
|
363
|
+
[]
|
|
364
|
+
>>> IndividuallyOverridableACAB().ignore_missing_arg(False)
|
|
365
|
+
[]
|
|
366
|
+
"""
|
|
367
|
+
return ["--ignore-missing"] if ignore_missing else []
|
|
368
|
+
|
|
369
|
+
def renormalize_arg(self, renormalize: bool | None) -> list[str]:
|
|
370
|
+
"""
|
|
371
|
+
Returns ``--renormalize`` if applicable.
|
|
372
|
+
|
|
373
|
+
>>> IndividuallyOverridableACAB().renormalize_arg(True)
|
|
374
|
+
['--renormalize']
|
|
375
|
+
>>> IndividuallyOverridableACAB().renormalize_arg(None)
|
|
376
|
+
[]
|
|
377
|
+
>>> IndividuallyOverridableACAB().renormalize_arg(False)
|
|
378
|
+
[]
|
|
379
|
+
"""
|
|
380
|
+
return ["--renormalize"] if renormalize else []
|
|
381
|
+
|
|
382
|
+
def chmod_arg(self, chmod: Literal["+x", "-x"] | None):
|
|
383
|
+
"""
|
|
384
|
+
Return ``--chmod=+x`` or ``--chmod=-x`` if applicable.
|
|
385
|
+
|
|
386
|
+
>>> IndividuallyOverridableACAB().chmod_arg('+x')
|
|
387
|
+
['--chmod=+x']
|
|
388
|
+
>>> IndividuallyOverridableACAB().chmod_arg('-x')
|
|
389
|
+
['--chmod=-x']
|
|
390
|
+
>>> IndividuallyOverridableACAB().chmod_arg(None)
|
|
391
|
+
[]
|
|
392
|
+
"""
|
|
393
|
+
if chmod is None:
|
|
394
|
+
return []
|
|
395
|
+
return [f"--chmod={chmod}"]
|
|
396
|
+
|
|
397
|
+
def tree_ish_arg(self, tree_ish: str) -> list[str]:
|
|
398
|
+
"""
|
|
399
|
+
Return the required tree-ish identifier as a single-element list.
|
|
400
|
+
|
|
401
|
+
This value is typically a commit SHA, branch name, tag, or other valid tree reference
|
|
402
|
+
and is appended at the end of the formed git subcommand options, just before path(s).
|
|
403
|
+
|
|
404
|
+
>>> IndividuallyOverridableACAB().tree_ish_arg("HEAD")
|
|
405
|
+
['HEAD']
|
|
406
|
+
>>> IndividuallyOverridableACAB().tree_ish_arg("origin/main")
|
|
407
|
+
['origin/main']
|
|
408
|
+
>>> IndividuallyOverridableACAB().tree_ish_arg("a1b2c3d")
|
|
409
|
+
['a1b2c3d']
|
|
410
|
+
>>> IndividuallyOverridableACAB().tree_ish_arg("")
|
|
411
|
+
['']
|
|
412
|
+
"""
|
|
413
|
+
return [tree_ish]
|
|
414
|
+
|
|
415
|
+
def path_args(self, path: list[str] | None) -> list[str]:
|
|
416
|
+
"""
|
|
417
|
+
Return the list of paths (if any) passed to ``git add``.
|
|
418
|
+
|
|
419
|
+
If `path` is None or an empty list, this returns an empty list.
|
|
420
|
+
|
|
421
|
+
>>> IndividuallyOverridableACAB().path_args(["src", "README.md"])
|
|
422
|
+
['src', 'README.md']
|
|
423
|
+
>>> IndividuallyOverridableACAB().path_args([])
|
|
424
|
+
[]
|
|
425
|
+
>>> IndividuallyOverridableACAB().path_args(None)
|
|
426
|
+
[]
|
|
427
|
+
"""
|
|
428
|
+
return path if path else []
|
|
429
|
+
|
|
430
|
+
def pathspec_file_nul_arg(self, pathspec_file_nul: bool | None) -> list[str]:
|
|
431
|
+
"""
|
|
432
|
+
Returns ``--pathspec-file-nul`` if applicable.
|
|
433
|
+
|
|
434
|
+
>>> IndividuallyOverridableACAB().pathspec_file_nul_arg(True)
|
|
435
|
+
['--pathspec-file-nul']
|
|
436
|
+
>>> IndividuallyOverridableACAB().pathspec_file_nul_arg(None)
|
|
437
|
+
[]
|
|
438
|
+
>>> IndividuallyOverridableACAB().pathspec_file_nul_arg(False)
|
|
439
|
+
[]
|
|
440
|
+
"""
|
|
441
|
+
return ["--pathspec-file-nul"] if pathspec_file_nul else []
|
|
442
|
+
|
|
443
|
+
def pathspec_from_file_arg(
|
|
444
|
+
self, pathspec_from_file: Path | Literal["-"] | None
|
|
445
|
+
) -> list[str]:
|
|
446
|
+
"""
|
|
447
|
+
Returns --pathspec-from-file=<pathspec-file> if applicable.
|
|
448
|
+
|
|
449
|
+
>>> IndividuallyOverridableACAB().pathspec_from_file_arg(None)
|
|
450
|
+
[]
|
|
451
|
+
>>> IndividuallyOverridableACAB().pathspec_from_file_arg(Path('a-file.txt'))
|
|
452
|
+
['--pathspec-from-file=a-file.txt']
|
|
453
|
+
>>> IndividuallyOverridableACAB().pathspec_from_file_arg('-')
|
|
454
|
+
['--pathspec-from-file=-']
|
|
455
|
+
"""
|
|
456
|
+
if pathspec_from_file is None:
|
|
457
|
+
return []
|
|
458
|
+
return [f"--pathspec-from-file={str(pathspec_from_file)}"]
|
|
459
|
+
|
|
460
|
+
def pathspec_arg(self, *pathspecs: str | None) -> list[str]:
|
|
461
|
+
"""
|
|
462
|
+
Examples::
|
|
463
|
+
|
|
464
|
+
>>> IndividuallyOverridableACAB().pathspec_arg()
|
|
465
|
+
[]
|
|
466
|
+
|
|
467
|
+
>>> IndividuallyOverridableACAB().pathspec_arg('ano', 'the-txt')
|
|
468
|
+
['ano', 'the-txt']
|
|
469
|
+
|
|
470
|
+
>>> IndividuallyOverridableACAB().pathspec_arg('add.py')
|
|
471
|
+
['add.py']
|
|
472
|
+
|
|
473
|
+
>>> IndividuallyOverridableACAB().pathspec_arg('.')
|
|
474
|
+
['.']
|
|
475
|
+
|
|
476
|
+
>>> IndividuallyOverridableACAB().pathspec_arg('ad*', 'dir*/*8add')
|
|
477
|
+
['ad*', 'dir*/*8add']
|
|
478
|
+
|
|
479
|
+
>>> IndividuallyOverridableACAB().pathspec_arg('ad*', 'dir*/*8add', 'dir/subdir/*')
|
|
480
|
+
['ad*', 'dir*/*8add', 'dir/subdir/*']
|
|
481
|
+
|
|
482
|
+
:return: pathspecs in a list if supplied.
|
|
483
|
+
"""
|
|
484
|
+
return [pathspec for pathspec in pathspecs if pathspec is not None]
|