|
6 | 6 | from git.compat import defenc |
7 | 7 | from git.objects import Object |
8 | 8 | from git.objects.commit import Commit |
| 9 | +from git.refs.log import RefLog |
9 | 10 | from git.util import ( |
| 11 | + LockedFD, |
| 12 | + assure_directory_exists, |
| 13 | + hex_to_bin, |
10 | 14 | join_path, |
11 | 15 | join_path_native, |
12 | 16 | to_native_path_linux, |
13 | | - assure_directory_exists, |
14 | | - hex_to_bin, |
15 | | - LockedFD, |
16 | 17 | ) |
17 | | -from gitdb.exc import BadObject, BadName |
18 | | - |
19 | | -from .log import RefLog |
| 18 | +from gitdb.exc import BadName, BadObject |
20 | 19 |
|
21 | 20 | # typing ------------------------------------------------------------------ |
22 | 21 |
|
23 | 22 | from typing import ( |
24 | 23 | Any, |
25 | 24 | Iterator, |
26 | 25 | List, |
| 26 | + TYPE_CHECKING, |
27 | 27 | Tuple, |
28 | 28 | Type, |
29 | 29 | TypeVar, |
30 | 30 | Union, |
31 | | - TYPE_CHECKING, |
32 | 31 | cast, |
33 | 32 | ) |
34 | | -from git.types import Old_commit_ish, PathLike |
| 33 | +from git.types import AnyGitObject, PathLike |
35 | 34 |
|
36 | 35 | if TYPE_CHECKING: |
37 | | - from git.repo import Repo |
38 | | - from git.refs import Head, TagReference, RemoteReference, Reference |
39 | | - from .log import RefLogEntry |
40 | 36 | from git.config import GitConfigParser |
41 | 37 | from git.objects.commit import Actor |
| 38 | + from git.refs import Head, TagReference, RemoteReference, Reference |
| 39 | + from git.refs.log import RefLogEntry |
| 40 | + from git.repo import Repo |
42 | 41 |
|
43 | 42 |
|
44 | 43 | T_References = TypeVar("T_References", bound="SymbolicReference") |
@@ -278,7 +277,7 @@ def _get_ref_info(cls, repo: "Repo", ref_path: Union[PathLike, None]) -> Union[T |
278 | 277 | """ |
279 | 278 | return cls._get_ref_info_helper(repo, ref_path) |
280 | 279 |
|
281 | | - def _get_object(self) -> Old_commit_ish: |
| 280 | + def _get_object(self) -> AnyGitObject: |
282 | 281 | """ |
283 | 282 | :return: |
284 | 283 | The object our ref currently refers to. Refs can be cached, they will always |
@@ -345,17 +344,20 @@ def set_commit( |
345 | 344 |
|
346 | 345 | def set_object( |
347 | 346 | self, |
348 | | - object: Union[Old_commit_ish, "SymbolicReference", str], |
| 347 | + object: Union[AnyGitObject, "SymbolicReference", str], |
349 | 348 | logmsg: Union[str, None] = None, |
350 | 349 | ) -> "SymbolicReference": |
351 | 350 | """Set the object we point to, possibly dereference our symbolic reference |
352 | 351 | first. If the reference does not exist, it will be created. |
353 | 352 |
|
354 | 353 | :param object: |
355 | 354 | A refspec, a :class:`SymbolicReference` or an |
356 | | - :class:`~git.objects.base.Object` instance. :class:`SymbolicReference` |
357 | | - instances will be dereferenced beforehand to obtain the object they point |
358 | | - to. |
| 355 | + :class:`~git.objects.base.Object` instance. |
| 356 | +
|
| 357 | + * :class:`SymbolicReference` instances will be dereferenced beforehand to |
| 358 | + obtain the git object they point to. |
| 359 | + * :class:`~git.objects.base.Object` instances must represent git objects |
| 360 | + (:class:`~git.types.AnyGitObject`). |
359 | 361 |
|
360 | 362 | :param logmsg: |
361 | 363 | If not ``None``, the message will be used in the reflog entry to be written. |
@@ -404,22 +406,22 @@ def _get_reference(self) -> "SymbolicReference": |
404 | 406 |
|
405 | 407 | def set_reference( |
406 | 408 | self, |
407 | | - ref: Union[Old_commit_ish, "SymbolicReference", str], |
| 409 | + ref: Union[AnyGitObject, "SymbolicReference", str], |
408 | 410 | logmsg: Union[str, None] = None, |
409 | 411 | ) -> "SymbolicReference": |
410 | 412 | """Set ourselves to the given `ref`. |
411 | 413 |
|
412 | | - It will stay a symbol if the ref is a :class:`~git.refs.reference.Reference`. |
| 414 | + It will stay a symbol if the `ref` is a :class:`~git.refs.reference.Reference`. |
413 | 415 |
|
414 | | - Otherwise an Object, given as :class:`~git.objects.base.Object` instance or |
415 | | - refspec, is assumed and if valid, will be set which effectively detaches the |
416 | | - reference if it was a purely symbolic one. |
| 416 | + Otherwise a git object, specified as a :class:`~git.objects.base.Object` |
| 417 | + instance or refspec, is assumed. If it is valid, this reference will be set to |
| 418 | + it, which effectively detaches the reference if it was a purely symbolic one. |
417 | 419 |
|
418 | 420 | :param ref: |
419 | 421 | A :class:`SymbolicReference` instance, an :class:`~git.objects.base.Object` |
420 | | - instance, or a refspec string. Only if the ref is a |
421 | | - :class:`SymbolicReference` instance, we will point to it. Everything else is |
422 | | - dereferenced to obtain the actual object. |
| 422 | + instance (specifically an :class:`~git.types.AnyGitObject`), or a refspec |
| 423 | + string. Only if the ref is a :class:`SymbolicReference` instance, we will |
| 424 | + point to it. Everything else is dereferenced to obtain the actual object. |
423 | 425 |
|
424 | 426 | :param logmsg: |
425 | 427 | If set to a string, the message will be used in the reflog. |
|
0 commit comments