Create a new reference "name" which points to an object or to another reference. Based on the type and value of the target parameter, this method tries to guess whether it is a direct or a symbolic reference. Keyword arguments: force: bool If Tr
(
self,
name: str,
target: Oid | str,
force: bool = False,
message: str | None = None,
)
| 318 | # References |
| 319 | # |
| 320 | def create_reference( |
| 321 | self, |
| 322 | name: str, |
| 323 | target: Oid | str, |
| 324 | force: bool = False, |
| 325 | message: str | None = None, |
| 326 | ) -> 'Reference': |
| 327 | """Create a new reference "name" which points to an object or to |
| 328 | another reference. |
| 329 | |
| 330 | Based on the type and value of the target parameter, this method tries |
| 331 | to guess whether it is a direct or a symbolic reference. |
| 332 | |
| 333 | Keyword arguments: |
| 334 | |
| 335 | force: bool |
| 336 | If True references will be overridden, otherwise (the default) an |
| 337 | exception is raised. |
| 338 | |
| 339 | message: str |
| 340 | Optional message to use for the reflog. |
| 341 | |
| 342 | Examples:: |
| 343 | |
| 344 | repo.create_reference('refs/heads/foo', repo.head.target) |
| 345 | repo.create_reference('refs/tags/foo', 'refs/heads/master') |
| 346 | repo.create_reference('refs/tags/foo', 'bbb78a9cec580') |
| 347 | """ |
| 348 | direct = isinstance(target, Oid) or ( |
| 349 | all(c in hexdigits for c in target) |
| 350 | and GIT_OID_MINPREFIXLEN <= len(target) <= GIT_OID_HEXSZ |
| 351 | ) |
| 352 | |
| 353 | # duplicate isinstance call for mypy |
| 354 | if direct or isinstance(target, Oid): |
| 355 | return self.create_reference_direct(name, target, force, message=message) |
| 356 | |
| 357 | return self.create_reference_symbolic(name, target, force, message=message) |
| 358 | |
| 359 | def listall_references(self) -> list[str]: |
| 360 | """Return a list with all the references in the repository.""" |
no outgoing calls