Collection of configured remotes You can use this class to look up and manage the remotes configured in a repository. You can access repositories using index access. E.g. to look up the "origin" remote, you can use >>> repo.remotes["origin"]
| 396 | |
| 397 | |
| 398 | class RemoteCollection: |
| 399 | """Collection of configured remotes |
| 400 | |
| 401 | You can use this class to look up and manage the remotes configured |
| 402 | in a repository. You can access repositories using index |
| 403 | access. E.g. to look up the "origin" remote, you can use |
| 404 | |
| 405 | >>> repo.remotes["origin"] |
| 406 | """ |
| 407 | |
| 408 | def __init__(self, repo: BaseRepository) -> None: |
| 409 | self._repo = repo |
| 410 | |
| 411 | def __len__(self) -> int: |
| 412 | with utils.new_git_strarray() as names: |
| 413 | err = C.git_remote_list(names, self._repo._repo) |
| 414 | check_error(err) |
| 415 | return names.count |
| 416 | |
| 417 | def __iter__(self) -> Iterator[Remote]: |
| 418 | cremote = ffi.new('git_remote **') |
| 419 | for name in self._ffi_names(): |
| 420 | err = C.git_remote_lookup(cremote, self._repo._repo, name) |
| 421 | check_error(err) |
| 422 | |
| 423 | yield Remote(self._repo, cremote[0]) |
| 424 | |
| 425 | def __getitem__(self, name: str | int) -> Remote: |
| 426 | if isinstance(name, int): |
| 427 | return list(self)[name] |
| 428 | |
| 429 | cremote = ffi.new('git_remote **') |
| 430 | err = C.git_remote_lookup(cremote, self._repo._repo, to_bytes(name)) |
| 431 | check_error(err) |
| 432 | |
| 433 | return Remote(self._repo, cremote[0]) |
| 434 | |
| 435 | def _ffi_names(self) -> Generator['char_pointer', None, None]: |
| 436 | with utils.new_git_strarray() as names: |
| 437 | err = C.git_remote_list(names, self._repo._repo) |
| 438 | check_error(err) |
| 439 | for i in range(names.count): |
| 440 | yield names.strings[i] # type: ignore[index] |
| 441 | |
| 442 | def names(self) -> Generator[str | None, None, None]: |
| 443 | """An iterator over the names of the available remotes.""" |
| 444 | for name in self._ffi_names(): |
| 445 | yield maybe_string(name) |
| 446 | |
| 447 | def create(self, name: str, url: str, fetch: str | None = None) -> Remote: |
| 448 | """Create a new remote with the given name and url. Returns a <Remote> |
| 449 | object. |
| 450 | |
| 451 | If 'fetch' is provided, this fetch refspec will be used instead of the |
| 452 | default. |
| 453 | """ |
| 454 | cremote = ffi.new('git_remote **') |
| 455 |
no outgoing calls
no test coverage detected
searching dependent graphs…