qgis_deployment_toolbelt.profiles.profiles_handler_base module¶
Handle remote git repository.
Author: Julien Moura (https://github.com/guts).
Inspired from: QGIS Resource Sharing
- class qgis_deployment_toolbelt.profiles.profiles_handler_base.RemoteProfilesHandlerBase(source_repository_type: Literal['git_local', 'git_remote', 'http', 'local', 'remote'], branch_to_use: str | None = None)¶
Bases:
object
Common git repository handler using dulwich.
It’s designed to handle thoses cases:
the distant repository (source) is on a local network or drive
the distant repository (source) is on Internet (github.com, gitlab.com, gitlab.company.org…)
the local repository (destination) is on a local network or drive
- SOURCE_REPOSITORY_TYPE: Literal['git_local', 'git_remote', 'http', 'local', 'remote'] | None = None¶
- __init__(source_repository_type: Literal['git_local', 'git_remote', 'http', 'local', 'remote'], branch_to_use: str | None = None) None ¶
Object instanciation.
- Parameters:
source_repository_type (Literal["git_local", "git_remote", "local", "remote"]) – type of source repository
branch_to_use (str | None, optional) – branch to clone or checkout. If None, the source active branch will be used. Defaults to None.
- clone_or_pull(to_local_destination_path: Path, attempt: int = 1) Repo ¶
Clone or fetch/pull remote repository to local path. If this one doesn’t exist, it’s created. If fetch or pull action fail, it removes the existing folder and clone the remote again.
- Parameters:
to_local_destination_path (Path) – path to the folder where to clone (or pull)
attempt (int) – attempt count. If attempts < 2 and it fails, the destination path is completely removed before cloning again. Defaults to 1.
- Raises:
err – if something fails during clone or pull operations
- Returns:
the local repository object
- Return type:
Repo
- download(destination_local_path: Path) Repo ¶
Generic wrapper around the specific logic of this handler.
- Parameters:
destination_local_path (Path) – path to the local folder where to download
- Returns:
the local repository object
- Return type:
Repo
- get_active_branch_from_local_repository(local_git_repository_path: Path | None = None) str ¶
- Retrieve git active branch from a local repository. Mainly a checker and a
wrapper around dulwich logic.
- Parameters:
local_git_repository_path (Path | None, optional) – path to the local repository. If not defined, the SOURCE_REPOSITORY_PATH_OR_URL object’s attribute is used if it exists. Defaults to None.
- Raises:
NotGitRepository – if the path is not a valid Git Repository
- Returns:
branch name
- Return type:
- is_branch_existing_in_repository(branch_name: str | bytes, repository_path_or_url: Path | str | None = None) bool ¶
Determine if the given branch name is part of the given repository.
- Parameters:
- Raises:
NotGitRepository – if the path is not a valid Git Repository
- Returns:
True is the rbanch is part of given repository existing branches
- Return type:
- is_valid_git_repository(source_repository_path_or_url: Path | str | None = None, force_type: Literal['git_local', 'git_remote', 'local', 'remote'] | None = None, raise_error: bool = True) bool ¶
Determine if the given path or URL is a valid repository or not.
- Parameters:
source_repository_path_or_url (Path | str | None, optional) – _description_. Defaults to None.
force_type (Literal["git_local","local", "remote"], optional) – force git repository type to check. If None, it uses the SOURCE_REPOSITORY_TYPE attribute. Defaults None.
raise_error (bool, optional) – if True, it raises an exception. Defaults to True.
- Raises:
NotGitRepository – if given path or URL is not a valid Git repository
- Returns:
True if the given path or URL is a valid Git repository
- Return type: