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/base.py ADDED
@@ -0,0 +1,983 @@
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 datetime import datetime
12
+ from pathlib import Path
13
+ from typing import Protocol, override, Unpack, Self, overload, Literal
14
+
15
+ from vt.utils.commons.commons.core_py import UNSET, Unset
16
+ from vt.utils.commons.commons.op import RootDirOp
17
+ from vt.utils.errors.error_specs import ERR_DATA_FORMAT_ERR
18
+
19
+ from gitbolt.exceptions import GitExitingException
20
+ from gitbolt.models import GitOpts, GitAddOpts, GitLsTreeOpts, GitEnvVars
21
+ from gitbolt.ls_tree import LsTreeArgsValidator, UtilLsTreeArgsValidator
22
+ from gitbolt.add import AddArgsValidator, UtilAddArgsValidator
23
+ from gitbolt.hash_object import HashObjectArgsValidator, UtilHashObjectArgsValidator
24
+
25
+
26
+ class HasGitUnderneath[G: "Git"](Protocol):
27
+ """
28
+ Stores a reference to main git instance.
29
+ """
30
+
31
+ @property
32
+ @abstractmethod
33
+ def git(self) -> G:
34
+ """
35
+ :return: stored underlying git instance reference.
36
+ """
37
+ ...
38
+
39
+
40
+ class CanOverrideGitOpts(Protocol):
41
+ """
42
+ Can override main git command options.
43
+
44
+ For example, in ``git --no-pager log -1 master`` git command, ``--no-pager`` is the main command arg.
45
+ """
46
+
47
+ @abstractmethod
48
+ def git_opts_override(self, **overrides: Unpack[GitOpts]) -> Self:
49
+ """
50
+ Temporarily override options to the main git command before current subcommand runs.
51
+
52
+ Get a new ``Git`` object with the git main command options overridden.
53
+
54
+ All the parameters mirror options described in the `git documentation <https://git-scm.com/docs/git>`_.
55
+
56
+ For example, in ``git --no-pager log -1 master`` git command, ``--no-pager`` is the main command arg.
57
+
58
+ :return: instance with overridden git main command args.
59
+ """
60
+ ...
61
+
62
+
63
+ class CanOverrideGitEnvs(Protocol):
64
+ """
65
+ Can override main git command environment variables.
66
+
67
+ For example, in ``GIT_COMMITTER_NAME=vt git --no-pager commit -m "a message"`` git command,
68
+ ``GIT_COMMITTER_NAME=ss``, particularly ``GIT_COMMITTER_NAME`` is the git environment variable.
69
+ """
70
+
71
+ @abstractmethod
72
+ def git_envs_override(self, **overrides: Unpack[GitEnvVars]) -> Self:
73
+ """
74
+ Temporarily override environment variables supplied to the git command before current subcommand runs.
75
+
76
+ Get a new ``Git`` object with the git environment variables overridden.
77
+
78
+ All the environment variables mirror envs described in the `git documentation <https://git-scm.com/docs/git#_environment_variables>`_.
79
+
80
+ For example, in ``GIT_COMMITTER_NAME=vt git --no-pager commit -m "a message"`` git command,
81
+ ``GIT_COMMITTER_NAME=vt``, particularly ``GIT_COMMITTER_NAME`` is the git environment variable.
82
+
83
+ :return: instance with overridden git environment variables.
84
+ """
85
+ ...
86
+
87
+
88
+ class GitSubCommand(CanOverrideGitOpts, CanOverrideGitEnvs, Protocol):
89
+ """
90
+ Interface for git subcommands, such as:
91
+
92
+ * ``add``
93
+ * ``commit``
94
+ * ``pull``
95
+ * ...
96
+ etc.
97
+ """
98
+
99
+ @abstractmethod
100
+ def clone(self) -> Self:
101
+ """
102
+ :return: a clone of the underlying subcommand.
103
+ """
104
+ ...
105
+
106
+ @abstractmethod
107
+ def _subcmd_from_git(self, git: "Git") -> Self:
108
+ """
109
+ Protected. Intended for inheritance only.
110
+
111
+ :return: specific implementation of subcommand from ``git``.
112
+ """
113
+ ...
114
+
115
+
116
+ class LsTree(GitSubCommand, RootDirOp, Protocol):
117
+ """
118
+ Interface for ``git ls-tree`` command.
119
+ """
120
+
121
+ @abstractmethod
122
+ def ls_tree(self, tree_ish: str, **ls_tree_opts: Unpack[GitLsTreeOpts]) -> str:
123
+ """
124
+ All the parameters are mirrors of the parameters of ``git ls-tree`` CLI command
125
+ from `git ls-tree documentation <https://git-scm.com/docs/git-ls-tree>`_.
126
+
127
+ :param tree_ish: A tree-ish identifier (commit SHA, branch name, etc.).
128
+ :param ls_tree_opts: Keyword arguments mapping to supported options for ``git ls-tree``.
129
+ :return: ``ls-tree`` output.
130
+ """
131
+ ...
132
+
133
+ @override
134
+ def _subcmd_from_git(self, git: "Git") -> "LsTree":
135
+ return git.ls_tree_subcmd()
136
+
137
+ @property
138
+ def args_validator(self) -> LsTreeArgsValidator:
139
+ """
140
+ The argument validator for ``git ls-tree`` subcommand.
141
+
142
+ :return: a validator for ls_tree subcommand arguments.
143
+ """
144
+ return UtilLsTreeArgsValidator()
145
+
146
+
147
+ class Add(GitSubCommand, RootDirOp, Protocol):
148
+ """
149
+ Interface for ``git add`` command.
150
+ """
151
+
152
+ # TODO: `pathspec: str` -> `pathspec_or_path: str | Path`.
153
+ # This will make a convenience method for python use.
154
+ @overload
155
+ @abstractmethod
156
+ def add(
157
+ self, pathspec: str, *pathspecs: str, **add_opts: Unpack[GitAddOpts]
158
+ ) -> str:
159
+ """
160
+ Add files specified by a list of pathspec strings.
161
+ `pathspec_from_file` and `pathspec_file_null` are disallowed here.
162
+
163
+ Mirrors the parameters of ``git add`` CLI command
164
+ from `git add documentation <https://git-scm.com/docs/git-add>`_.
165
+
166
+ :return: output of ``git add``.
167
+ """
168
+
169
+ @overload
170
+ @abstractmethod
171
+ def add(
172
+ self,
173
+ *,
174
+ pathspec_from_file: Path,
175
+ pathspec_file_nul: bool = False,
176
+ **add_opts: Unpack[GitAddOpts],
177
+ ) -> str:
178
+ """
179
+ Add files listed in a file (`pathspec_from_file`) to the index.
180
+ `pathspec_file_null` indicates if the file is NUL terminated.
181
+ No explicit pathspec list is allowed in this overload.
182
+
183
+ Mirrors the parameters of ``git add`` CLI command
184
+ from `git add documentation <https://git-scm.com/docs/git-add>`_.
185
+
186
+ :return: output of ``git add``.
187
+ """
188
+
189
+ @overload
190
+ @abstractmethod
191
+ def add(
192
+ self,
193
+ *,
194
+ pathspec_from_file: Literal["-"],
195
+ pathspec_stdin: str,
196
+ pathspec_file_nul: bool = False,
197
+ **add_opts: Unpack[GitAddOpts],
198
+ ) -> str:
199
+ """
200
+ Add files listed from stdin (when `pathspec_from_file` is '-').
201
+ The `pathspec_stdin` argument is the string content piped to stdin.
202
+
203
+ Mirrors the parameters of ``git add`` CLI command
204
+ from `git add documentation <https://git-scm.com/docs/git-add>`_.
205
+
206
+ :return: output of ``git add``.
207
+ """
208
+
209
+ @property
210
+ def args_validator(self) -> AddArgsValidator:
211
+ """
212
+ The argument validator for ``git add`` subcommand.
213
+
214
+ :return: a validator for add subcommand arguments.
215
+ """
216
+ return UtilAddArgsValidator()
217
+
218
+ @override
219
+ def _subcmd_from_git(self, git: "Git") -> "Add":
220
+ return git.add_subcmd()
221
+
222
+
223
+ class Version(GitSubCommand, Protocol):
224
+ """
225
+ Interface for ``git version`` command.
226
+ """
227
+
228
+ class VersionInfo:
229
+ @abstractmethod
230
+ def version(self) -> str: ...
231
+
232
+ @abstractmethod
233
+ def semver(self) -> tuple: ...
234
+
235
+ class VersionWithBuildInfo(VersionInfo):
236
+ @abstractmethod
237
+ def build_options(self) -> dict[str, str]: ...
238
+
239
+ @overload
240
+ @abstractmethod
241
+ def version(self) -> VersionInfo: ...
242
+
243
+ @overload
244
+ @abstractmethod
245
+ def version(self, build_options: Literal[True]) -> VersionWithBuildInfo: ...
246
+
247
+ @abstractmethod
248
+ def version(
249
+ self, build_options: Literal[True, False] = False
250
+ ) -> VersionInfo | VersionWithBuildInfo:
251
+ """
252
+ All the parameters are mirrors of the parameters of ``git version`` CLI command
253
+ from `git version documentation <https://git-scm.com/docs/git-version>`_.
254
+
255
+ :return: ``version`` output.
256
+ """
257
+ ...
258
+
259
+ @staticmethod
260
+ def _require_valid_args(build_options: bool = False) -> None:
261
+ """
262
+ Require that arguments sent to the version command is valid.
263
+
264
+ Examples:
265
+
266
+ Correct:
267
+
268
+ >>> Version._require_valid_args()
269
+
270
+ Error:
271
+
272
+ >>> Version._require_valid_args(1) # type: ignore[arg-type] # required bool, supplied int
273
+ Traceback (most recent call last):
274
+ gitbolt.exceptions.GitExitingException: TypeError: build_options should be bool.
275
+
276
+ :param build_options: argument to be validated.
277
+ :raise GitExitingException: if supplied ``build_options`` is invalid.
278
+ """
279
+ if not isinstance(build_options, bool):
280
+ errmsg = "build_options should be bool."
281
+ raise GitExitingException(
282
+ errmsg, exit_code=ERR_DATA_FORMAT_ERR
283
+ ) from TypeError(errmsg)
284
+
285
+ @override
286
+ def _subcmd_from_git(self, git: "Git") -> "Version":
287
+ return git.version_subcmd()
288
+
289
+
290
+ class Worktree(GitSubCommand, RootDirOp, Protocol):
291
+ """
292
+ Interface for ``git worktree`` subcommand.
293
+ """
294
+
295
+ class WorktreeSubcmd(RootDirOp, Protocol):
296
+ """
297
+ Interface for the worktree subcommands.
298
+ """
299
+
300
+ @property
301
+ @abstractmethod
302
+ def underlying_worktree(self) -> Worktree:
303
+ """
304
+ :return: underlying worktree for this subcommand.
305
+ """
306
+ ...
307
+
308
+ @abstractmethod
309
+ def clone(self) -> "Worktree.WorktreeSubcmd":
310
+ """
311
+ :return: a clone of the underlying worktree subcommand.
312
+ """
313
+ ...
314
+
315
+ @abstractmethod
316
+ def _subcmd_from_worktree(self, worktree: "Worktree") -> "Worktree.WorktreeSubcmd":
317
+ """
318
+ Protected. Intended for inheritance only.
319
+
320
+ :return: specific implementation of subcommand from ``worktree``.
321
+ """
322
+ ...
323
+
324
+ # region worktree list subcommands
325
+ class List(WorktreeSubcmd, Protocol):
326
+ """
327
+ Interface for ``git worktree list`` subcommand.
328
+ """
329
+
330
+ @abstractmethod
331
+ @overload
332
+ def list(self, *, verbose: bool = False) -> str:
333
+ ...
334
+
335
+ @abstractmethod
336
+ @overload
337
+ def list(self, *, porcelain: Literal[False]) -> str:
338
+ ...
339
+
340
+ @abstractmethod
341
+ @overload
342
+ def list(self, *, porcelain: Literal[True], z: Literal[True] | Unset = UNSET) -> str:
343
+ ...
344
+
345
+ @abstractmethod
346
+ def list(self, *, verbose: bool | Unset = UNSET, porcelain: Literal[True, False] | Unset = UNSET,
347
+ z: Literal[True] | Unset = UNSET) -> str:
348
+ """
349
+ List all the worktrees.
350
+
351
+ ``git worktree list`` documentation: https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt-list
352
+
353
+ :param verbose: https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt---verbose
354
+ :param porcelain: https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt---porcelain
355
+ :param z: This option can only be used if porcelain is enabled. See
356
+ https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt--z for more details.
357
+ :returns: stdout of the command run.
358
+ """
359
+ ...
360
+
361
+ @override
362
+ def _subcmd_from_worktree(self, worktree: "Worktree") -> Worktree.List:
363
+ return worktree.list_subcmd()
364
+
365
+ @abstractmethod
366
+ def list_subcmd(self) -> Worktree.List:
367
+ """
368
+ :returns: ``git worktree list`` subcommand.
369
+ """
370
+ ...
371
+
372
+ # endregion
373
+
374
+ # region worktree lock subcommands
375
+ class Lock(WorktreeSubcmd, Protocol):
376
+ """
377
+ Interface for ``git worktree lock`` subcommand.
378
+ """
379
+
380
+ @abstractmethod
381
+ def lock(self, worktree: Path, reason: str | Literal[False] | Unset = UNSET) -> str:
382
+ """
383
+ Lock a worktree to prevent administrative files form being pruned automatically.
384
+
385
+ `git worktree lock documentation
386
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt-lock>`_.
387
+
388
+ :param worktree: Path to the worktree that is to be locked.
389
+ :param reason: `a reason for why a worktree is locked
390
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt-lock>`_.
391
+ :return: git worktree lock output.
392
+ """
393
+ ...
394
+
395
+ @override
396
+ def _subcmd_from_worktree(self, worktree: "Worktree") -> Worktree.Lock:
397
+ return worktree.lock_subcmd()
398
+
399
+ @abstractmethod
400
+ def lock_subcmd(self) -> Worktree.Lock:
401
+ """
402
+ :returns: ``git worktree lock`` subcommand.
403
+ """
404
+ ...
405
+
406
+ # endregion
407
+
408
+ # region worktree unlock subcommands
409
+ class UnLock(WorktreeSubcmd, Protocol):
410
+ """
411
+ Interface for ``git worktree unlock`` subcommand.
412
+ """
413
+
414
+ @abstractmethod
415
+ def unlock(self, worktree: Path) -> str:
416
+ """
417
+ Unlock a locked worktree for pruning or deletion.
418
+
419
+ `git worktree unlock documentation
420
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt-unlock>`_.
421
+
422
+ :param worktree: Path to the worktree that is to be unlocked.
423
+ :return: git worktree unlock output.
424
+ """
425
+ ...
426
+
427
+ @override
428
+ def _subcmd_from_worktree(self, worktree: "Worktree") -> Worktree.UnLock:
429
+ return worktree.unlock_subcmd()
430
+
431
+ @abstractmethod
432
+ def unlock_subcmd(self) -> Worktree.UnLock:
433
+ """
434
+ :returns: ``git worktree unlock`` subcommand.
435
+ """
436
+ ...
437
+
438
+ # endregion
439
+
440
+ # region worktree move subcommands
441
+ class Move(WorktreeSubcmd, Protocol):
442
+ """
443
+ Interface for ``git worktree move`` subcommand.
444
+ """
445
+
446
+ @abstractmethod
447
+ def move(self, worktree: Path, new_path: Path, *, force: bool | Unset = UNSET, reforce: bool | Unset = UNSET,
448
+ relative_paths: bool | Unset = UNSET) -> str:
449
+ """
450
+ Move the worktree. Documentation: https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt-move
451
+
452
+ Also, info on ``git worktree move -h``.
453
+
454
+ :param worktree: Path to the worktree that is to be moved.
455
+ :param new_path: Path where the worktree is to be moved.
456
+ :param force: `force move a worktree even when it is locked <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt---force>`_.
457
+ :param reforce: multiple force arguments for moving a locked worktree.
458
+ :param relative_paths: `use relative paths for worktree <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt---no-relative-paths>`_.
459
+ :return: output of ``git worktree move``.
460
+ """
461
+ ...
462
+
463
+ @override
464
+ def _subcmd_from_worktree(self, worktree: "Worktree") -> Worktree.Move:
465
+ return worktree.move_subcmd()
466
+
467
+ @abstractmethod
468
+ def move_subcmd(self) -> Worktree.Move:
469
+ """
470
+ :returns: ``git worktree move`` subcommand.
471
+ """
472
+ ...
473
+
474
+ # endregion
475
+
476
+ # region worktree prune subcommands
477
+ class Prune(WorktreeSubcmd, Protocol):
478
+ """
479
+ Interface for ``git worktree prune`` subcommand.
480
+
481
+ Documentation: https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt-prune
482
+ """
483
+
484
+ @abstractmethod
485
+ def prune(self, *, dry_run: bool | Unset = UNSET, verbose: bool | Unset = UNSET,
486
+ expire: Literal[False] | int | datetime | Unset = UNSET) -> str:
487
+ """
488
+ Prune worktrees satisfying pruning conditions.
489
+
490
+ :param dry_run: `Just dry run the operation and do not actually prune anything.
491
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt---dry-run>`_.
492
+ :param verbose: `be verbose while pruning
493
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt---verbose>`_.
494
+ :param expire: `prune worktrees older than this expiration time
495
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt---expiretime>`_.
496
+ :returns: prune output in string format.
497
+ """
498
+ ...
499
+
500
+ @override
501
+ def _subcmd_from_worktree(self, worktree: "Worktree") -> Worktree.Prune:
502
+ return worktree.prune_subcmd()
503
+
504
+ @abstractmethod
505
+ def prune_subcmd(self) -> Worktree.Prune:
506
+ """
507
+ :returns: ``git worktree prune`` subcommand.
508
+ """
509
+ ...
510
+ # endregion
511
+
512
+ # region worktree remove subcommands
513
+ class Remove(WorktreeSubcmd, Protocol):
514
+ """
515
+ Interface for ``git worktree remove`` subcommand.
516
+
517
+ Documentation: https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt-remove
518
+ """
519
+
520
+ @abstractmethod
521
+ def remove(self, worktree: Path, *, force: bool | Unset = UNSET, reforce: bool | Unset = UNSET) -> str:
522
+ """
523
+ Remove worktree.
524
+
525
+ :param worktree: path of the worktree to remove.
526
+ :param force: `force remove this worktree
527
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt---force>`_.
528
+ :param reforce: unclean but locked worktree needs multiple force arguments for worktree removal.
529
+ :returns: remove output in string format.
530
+ """
531
+ ...
532
+
533
+ @override
534
+ def _subcmd_from_worktree(self, worktree: "Worktree") -> Worktree.Remove:
535
+ return worktree.remove_subcmd()
536
+
537
+ @abstractmethod
538
+ def remove_subcmd(self) -> Worktree.Remove:
539
+ """
540
+ :returns: ``git worktree remove`` subcommand.
541
+ """
542
+ ...
543
+ # endregion
544
+
545
+ # region worktree repair subcommands
546
+ class Repair(WorktreeSubcmd, Protocol):
547
+ """
548
+ Interface for ``git worktree repair`` subcommand.
549
+
550
+ Documentation: https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt-repair
551
+ """
552
+
553
+ @abstractmethod
554
+ def repair(self, *worktrees: Path, relative_paths: Unset | bool = UNSET) -> str:
555
+ """
556
+ Repair worktree(s).
557
+
558
+ :param worktrees: paths of the worktree to repair.
559
+ :param relative_paths: `use relative paths for worktree
560
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt---relative-paths>`_.
561
+ :returns: remove output in string format.
562
+ """
563
+ ...
564
+
565
+ @override
566
+ def _subcmd_from_worktree(self, worktree: "Worktree") -> Worktree.Repair:
567
+ return worktree.repair_subcmd()
568
+
569
+ @abstractmethod
570
+ def repair_subcmd(self) -> Worktree.Repair:
571
+ """
572
+ :returns: ``git worktree repair`` subcommand.
573
+ """
574
+ ...
575
+ # endregion
576
+
577
+ # region worktree add subcommand
578
+ class Add(WorktreeSubcmd, Protocol):
579
+ """
580
+ Interface for ``git worktree add`` subcommand.
581
+
582
+ Documentation: https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt-add
583
+ """
584
+
585
+ def add(self, worktree: Path, commit_ish: str | None = None, *, force: bool | Unset = UNSET,
586
+ reforce: bool | Unset = UNSET, new_branch: str | Unset = UNSET, new_branch_force: str | Unset = UNSET,
587
+ orphan: Literal[True] | Unset = UNSET, detach: Literal[True] | Unset = UNSET,
588
+ checkout: bool | Unset = UNSET, lock: bool | Unset = UNSET,
589
+ reason: str | Literal[False] | Unset = UNSET, quiet: bool | Unset = UNSET,
590
+ track: bool | Unset = UNSET, guess_remote: bool | Unset = UNSET,
591
+ relative_paths: bool | Unset = UNSET) -> str:
592
+ """
593
+ Add worktree.
594
+
595
+ :param worktree: path of the worktree to add.
596
+ :param commit_ish: `add a worktree by checking out commit-ish
597
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt-addpathcommit-ish>`_.
598
+ :param force: `force remove this worktree
599
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt---force>`_.
600
+ :param reforce: add a missing but locked worktree path.
601
+ :param new_branch: `add a new branch for worktree.
602
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt-addpathcommit-ish>`_.
603
+ :param new_branch_force: `add a new branch for worktree. Creates a branch at commit_ish even if it
604
+ exists already
605
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt-addpathcommit-ish>`_.
606
+ :param orphan: `orphan unborn branch worktree
607
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt-addpathcommit-ish>`_.
608
+ :param detach: `create a detached worktree
609
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt---detach>`_.
610
+ :param checkout: `checkout the branch in worktree
611
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt---checkout>`_.
612
+ :param lock: `keep the worktree locked after creation
613
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt---lock>`_.
614
+ :param reason: `explanation of why a worktree is locked
615
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt---reasonstring>`_.
616
+ :param quiet: `suppress add feedback messages
617
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt---quiet>`_.
618
+ :param track: `track certain upstream branch
619
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt---track>`_.
620
+ :param guess_remote: `check if a branch already exists on remote that matches this one
621
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt---guess-remote>`_.
622
+ :param relative_paths: `link worktrees using relative paths instead of absolute path (the default)
623
+ <https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt---relative-paths>`_.
624
+ :returns: add output in string format.
625
+ """
626
+ ...
627
+
628
+ @override
629
+ def _subcmd_from_worktree(self, worktree: "Worktree") -> Worktree.Add:
630
+ return worktree.add_subcmd()
631
+
632
+
633
+ @abstractmethod
634
+ def add_subcmd(self) -> Worktree.Add:
635
+ """
636
+ :returns: ``git worktree add`` subcommand.
637
+ """
638
+ ...
639
+ # endregion
640
+
641
+ @override
642
+ def _subcmd_from_git(self, git: "Git") -> "Worktree":
643
+ return git.worktree_subcmd()
644
+
645
+
646
+ class HashObject(GitSubCommand, Protocol):
647
+ """
648
+ Interface for ``git hash-object`` subcommand. Can only calculate hashes and does not write objects to git.
649
+ """
650
+
651
+ # region hash_object and overloads
652
+ @overload
653
+ @abstractmethod
654
+ def hash_object(self, file_path: Path, *, t: Literal["commit", "tree", "blob", "tag"] = "blob",
655
+ path: Path | None = None, literally: bool = False) -> str:
656
+ """
657
+ Compute the object ID of a file without writing it to the object database.
658
+
659
+ Mirrors ``git hash-object`` from `git hash-object documentation <https://git-scm.com/docs/git-hash-object>`_.
660
+
661
+ :param file_path: Path of the file to hash.
662
+ :param t: Object type (``blob``, ``commit``, ``tree``, or ``tag``).
663
+ :param path: Virtual path used to select attributes and filters.
664
+ :param literally: Allow an object type that would otherwise fail fsck.
665
+ :return: Object hash.
666
+ """
667
+ ...
668
+
669
+ @overload
670
+ @abstractmethod
671
+ def hash_object(self, file_path: Path, *, t: Literal["commit", "tree", "blob", "tag"] = "blob",
672
+ no_filters: bool = False, literally: bool = False) -> str:
673
+ """
674
+ Compute the object ID of a file without writing it to the object database.
675
+
676
+ ``path`` and ``no_filters`` cannot be combined.
677
+
678
+ :param file_path: Path of the file to hash.
679
+ :param t: Object type (``blob``, ``commit``, ``tree``, or ``tag``).
680
+ :param no_filters: Hash the file as-is, without converting CRLF or applying filters.
681
+ :param literally: Allow an object type that would otherwise fail fsck.
682
+ :return: Object hash.
683
+ """
684
+ ...
685
+
686
+ @overload
687
+ @abstractmethod
688
+ def hash_object(self, file_path: Path, *file_paths: Path, t: Literal["commit", "tree", "blob", "tag"] = "blob",
689
+ no_filters: bool = False, literally: bool = False, stdin: bytes | None = None) -> list[str]:
690
+ """
691
+ Compute object IDs for one or more files, optionally hashing ``stdin`` first.
692
+
693
+ :param file_path: First file to hash.
694
+ :param file_paths: Additional files to hash in the same invocation.
695
+ :param t: Object type (``blob``, ``commit``, ``tree``, or ``tag``).
696
+ :param no_filters: Hash files as-is, without converting CRLF or applying filters.
697
+ :param literally: Allow an object type that would otherwise fail fsck.
698
+ :param stdin: Optional bytes hashed with ``--stdin`` before the files.
699
+ :return: Object hashes, one per hashed input.
700
+ """
701
+ ...
702
+
703
+ @overload
704
+ @abstractmethod
705
+ def hash_object(self, file_path: Path, *file_paths: Path, t: Literal["commit", "tree", "blob", "tag"] = "blob",
706
+ path: Path | None = None, literally: bool = False, stdin: bytes | None = None) -> list[str]:
707
+ """
708
+ Compute object IDs for one or more files, optionally hashing ``stdin`` first.
709
+
710
+ ``path`` and ``no_filters`` cannot be combined.
711
+
712
+ :param file_path: First file to hash.
713
+ :param file_paths: Additional files to hash in the same invocation.
714
+ :param t: Object type (``blob``, ``commit``, ``tree``, or ``tag``).
715
+ :param path: Virtual path used to select attributes and filters.
716
+ :param literally: Allow an object type that would otherwise fail fsck.
717
+ :param stdin: Optional bytes hashed with ``--stdin`` before the files.
718
+ :return: Object hashes, one per hashed input.
719
+ """
720
+ ...
721
+
722
+ @overload
723
+ @abstractmethod
724
+ def hash_object(self, *, stdin: bytes, t: Literal["commit", "tree", "blob", "tag"] = "blob",
725
+ path: Path | None = None, literally: bool = False) -> str:
726
+ """
727
+ Compute the object ID of bytes from standard input.
728
+
729
+ :param stdin: Bytes to hash with ``--stdin``.
730
+ :param t: Object type (``blob``, ``commit``, ``tree``, or ``tag``).
731
+ :param path: Virtual path used to select attributes and filters.
732
+ :param literally: Allow an object type that would otherwise fail fsck.
733
+ :return: Object hash.
734
+ """
735
+ ...
736
+
737
+ @overload
738
+ @abstractmethod
739
+ def hash_object(self, *, stdin: bytes, t: Literal["commit", "tree", "blob", "tag"] = "blob",
740
+ no_filters: bool = False, literally: bool = False) -> str:
741
+ """
742
+ Compute the object ID of bytes from standard input.
743
+
744
+ ``path`` and ``no_filters`` cannot be combined.
745
+
746
+ :param stdin: Bytes to hash with ``--stdin``.
747
+ :param t: Object type (``blob``, ``commit``, ``tree``, or ``tag``).
748
+ :param no_filters: Hash the bytes as-is, without converting CRLF or applying filters.
749
+ :param literally: Allow an object type that would otherwise fail fsck.
750
+ :return: Object hash.
751
+ """
752
+ ...
753
+
754
+ @overload
755
+ @abstractmethod
756
+ def hash_object(self, *, stdin_paths: list[Path],
757
+ t: Literal["commit", "tree", "blob", "tag"] = "blob",
758
+ no_filters: bool = False, literally: bool = False) -> list[str]:
759
+ """
760
+ Compute object IDs for paths read from standard input.
761
+
762
+ ``stdin_paths`` cannot be combined with file paths, ``stdin``, or ``path``.
763
+
764
+ :param stdin_paths: Paths hashed with ``--stdin-paths``.
765
+ :param t: Object type (``blob``, ``commit``, ``tree``, or ``tag``).
766
+ :param no_filters: Hash files as-is, without converting CRLF or applying filters.
767
+ :param literally: Allow an object type that would otherwise fail fsck.
768
+ :return: Object hashes, one per path.
769
+ """
770
+ ...
771
+
772
+ @abstractmethod
773
+ def multi_hash_objects(self, stdin: bytes, *stdins: bytes,
774
+ t: Literal["commit", "tree", "blob", "tag"] = "blob",
775
+ no_filters: bool = False, literally: bool = False,
776
+ tmpdir: Path | None = None) -> list[str]:
777
+ """
778
+ Hash multiple stdin payloads in one ``git hash-object`` process.
779
+
780
+ This is a GitBolt utility method. Git ``hash-object`` has no ``multi_hash_objects``
781
+ subcommand or flag; each stdin is written to a temporary file and those paths are
782
+ hashed together in a single process.
783
+ If ``tmpdir`` is omitted, a temporary directory is created and cleaned up.
784
+
785
+ :param stdin: First bytes payload to hash.
786
+ :param stdins: Additional bytes payloads to hash.
787
+ :param t: Object type (``blob``, ``commit``, ``tree``, or ``tag``).
788
+ :param no_filters: Hash files as-is, without converting CRLF or applying filters.
789
+ :param literally: Allow an object type that would otherwise fail fsck.
790
+ :param tmpdir: Directory for the temporary files. Created when omitted.
791
+ :return: Object hashes, one per stdin payload.
792
+ """
793
+ ...
794
+ # endregion
795
+
796
+ @override
797
+ def _subcmd_from_git(self, git: 'Git') -> HashObject:
798
+ return git.hash_object_subcmd()
799
+
800
+ def args_validator(self) -> HashObjectArgsValidator:
801
+ """
802
+ The argument validator for ``git hash-object`` subcommand.
803
+
804
+ :return: a validator for hash_object subcommand arguments.
805
+ """
806
+ return UtilHashObjectArgsValidator()
807
+
808
+ @abstractmethod
809
+ def writing(self) -> WritingHashObject:
810
+ """
811
+ :return: ``git hash-object`` subcommand which can write objects to git.
812
+ """
813
+ ...
814
+
815
+
816
+ class WritingHashObject(HashObject, RootDirOp, Protocol):
817
+ """
818
+ Interface for ``git hash-object`` subcommand which can write objects to git.
819
+ """
820
+
821
+ # region hash_object and overloads
822
+ @overload
823
+ @abstractmethod
824
+ def hash_object(self, file_path: Path, *, t: Literal["commit", "tree", "blob", "tag"] = "blob",
825
+ path: Path | None = None, literally: bool = False, w: bool = False) -> str:
826
+ ...
827
+
828
+ @overload
829
+ @abstractmethod
830
+ def hash_object(self, file_path: Path, *, t: Literal["commit", "tree", "blob", "tag"] = "blob",
831
+ no_filters: bool = False, literally: bool = False, w: bool = False) -> str:
832
+ ...
833
+
834
+ @overload
835
+ @abstractmethod
836
+ def hash_object(self, file_path: Path, *file_paths: Path, t: Literal["commit", "tree", "blob", "tag"] = "blob",
837
+ no_filters: bool = False, literally: bool = False, stdin: bytes | None = None,
838
+ w: bool = False) -> list[str]:
839
+ ...
840
+
841
+ @overload
842
+ @abstractmethod
843
+ def hash_object(self, file_path: Path, *file_paths: Path, t: Literal["commit", "tree", "blob", "tag"] = "blob",
844
+ path: Path | None = None, literally: bool = False, stdin: bytes | None = None,
845
+ w: bool = False) -> list[str]:
846
+ ...
847
+
848
+ @overload
849
+ @abstractmethod
850
+ def hash_object(self, *, stdin: bytes, t: Literal["commit", "tree", "blob", "tag"] = "blob",
851
+ path: Path | None = None, literally: bool = False, w: bool = False) -> str:
852
+ ...
853
+
854
+ @overload
855
+ @abstractmethod
856
+ def hash_object(self, *, stdin: bytes, t: Literal["commit", "tree", "blob", "tag"] = "blob",
857
+ no_filters: bool = False, literally: bool = False, w: bool = False) -> str:
858
+ ...
859
+
860
+ @overload
861
+ @abstractmethod
862
+ def hash_object(self, *, stdin_paths: list[Path],
863
+ t: Literal["commit", "tree", "blob", "tag"] = "blob",
864
+ no_filters: bool = False, literally: bool = False, w: bool = False) -> list[str]:
865
+ ...
866
+
867
+ @override
868
+ @abstractmethod
869
+ def multi_hash_objects(self, stdin: bytes, *stdins: bytes,
870
+ t: Literal["commit", "tree", "blob", "tag"] = "blob",
871
+ no_filters: bool = False, literally: bool = False, w: bool = False,
872
+ tmpdir: Path | None = None) -> list[str]:
873
+ """
874
+ Hash multiple stdin payloads in one ``git hash-object`` process.
875
+
876
+ This is a GitBolt utility method. Git ``hash-object`` has no ``multi_hash_objects``
877
+ subcommand or flag.
878
+
879
+ :param stdin: First bytes payload to hash.
880
+ :param stdins: Additional bytes payloads to hash.
881
+ :param t: Object type (``blob``, ``commit``, ``tree``, or ``tag``).
882
+ :param no_filters: Hash files as-is, without converting CRLF or applying filters.
883
+ :param literally: Allow an object type that would otherwise fail fsck.
884
+ :param w: Write the resulting objects into the object database.
885
+ :param tmpdir: Directory for the temporary files. Created when omitted.
886
+ :return: Object hashes, one per stdin payload.
887
+ """
888
+ ...
889
+
890
+ # endregion
891
+
892
+ @override
893
+ def _subcmd_from_git(self, git: 'Git') -> WritingHashObject:
894
+ return git.writing_hash_object_subcmd()
895
+
896
+
897
+ class Git(CanOverrideGitOpts, CanOverrideGitEnvs, Protocol):
898
+ """
899
+ Class designed analogous to documentation provided on `git documentation <https://git-scm.com/docs/git>`_.
900
+ """
901
+
902
+ def version(self) -> Version.VersionInfo:
903
+ """
904
+ :return: current git version.
905
+ """
906
+ return self.version_subcmd().version()
907
+
908
+ @abstractmethod
909
+ def exec_path(self) -> Path:
910
+ """
911
+ :return: Path to wherever your core Git programs are installed.
912
+ """
913
+ ...
914
+
915
+ @abstractmethod
916
+ def html_path(self) -> Path:
917
+ """
918
+ :return: the path, without trailing slash, where Git’s HTML documentation is installed.
919
+ """
920
+ ...
921
+
922
+ @abstractmethod
923
+ def info_path(self) -> Path:
924
+ """
925
+ :return: the path where the Info files documenting this version of Git are installed.
926
+ """
927
+ ...
928
+
929
+ @abstractmethod
930
+ def man_path(self) -> Path:
931
+ """
932
+ :return: the man path (see man(1)) for the man pages for this version of Git.
933
+ """
934
+ ...
935
+
936
+ @abstractmethod
937
+ def version_subcmd(self) -> Version:
938
+ """
939
+ :return: ``git version`` subcommand.
940
+ """
941
+ ...
942
+
943
+ @abstractmethod
944
+ def ls_tree_subcmd(self) -> LsTree:
945
+ """
946
+ :return: ``git ls-tree`` subcommand.
947
+ """
948
+ ...
949
+
950
+ @abstractmethod
951
+ def add_subcmd(self) -> Add:
952
+ """
953
+ :return: ``git add`` subcommand.
954
+ """
955
+ ...
956
+
957
+ @abstractmethod
958
+ def hash_object_subcmd(self) -> HashObject:
959
+ """
960
+ :return: ``git hash-object`` subcommand. Can calculate hashes but cannot write objects to the git database.
961
+ """
962
+ ...
963
+
964
+ @abstractmethod
965
+ def writing_hash_object_subcmd(self) -> WritingHashObject:
966
+ """
967
+ :return: ``git hash-object`` subcommand. Can write objects to the git database.
968
+ """
969
+ ...
970
+
971
+ @abstractmethod
972
+ def worktree_subcmd(self) -> Worktree:
973
+ """
974
+ :return: ``git worktree`` subcommand.
975
+ """
976
+ ...
977
+
978
+ @abstractmethod
979
+ def clone(self) -> Self:
980
+ """
981
+ :return: a clone of this class.
982
+ """
983
+ ...