Skip to content

temp_git_repo

This module contains the TempGitRemote class.

TempGitRemote

Context manager class for creating and cleaning up a temporary git remote.

Source code in ssb_project_cli/ssb_project/create/temp_git_repo.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class TempGitRemote:
    """Context manager class for creating and cleaning up a temporary git remote."""

    def __init__(self, repo: Repo, temp_url: str, restore_url: str) -> None:
        """Inits a TempGitRepo.

        Args:
            repo: Git repository
            temp_url: Temp url
            restore_url: Restore url
        """
        self.repo = repo
        self.temp_url = temp_url
        self.restore_url = restore_url

    def __enter__(self) -> None:
        """Deletes remote in Repository and creates remote at temp_url."""
        for remote in self.repo.remotes:
            self.repo.delete_remote(remote)
        self.origin = self.repo.create_remote("origin", self.temp_url)
        return None

    # Look up
    def __exit__(
        self,
        exc_type: Optional[Type[BaseException]],
        exc_val: Optional[BaseException],
        exc_tb: Optional[TracebackType],
    ) -> None:
        """Deletes remote self.origin and creates a remote named origin with an url."""
        self.repo.delete_remote(self.origin)
        self.repo.create_remote("origin", self.restore_url)

__enter__()

Deletes remote in Repository and creates remote at temp_url.

Source code in ssb_project_cli/ssb_project/create/temp_git_repo.py
25
26
27
28
29
30
def __enter__(self) -> None:
    """Deletes remote in Repository and creates remote at temp_url."""
    for remote in self.repo.remotes:
        self.repo.delete_remote(remote)
    self.origin = self.repo.create_remote("origin", self.temp_url)
    return None

__exit__(exc_type, exc_val, exc_tb)

Deletes remote self.origin and creates a remote named origin with an url.

Source code in ssb_project_cli/ssb_project/create/temp_git_repo.py
33
34
35
36
37
38
39
40
41
def __exit__(
    self,
    exc_type: Optional[Type[BaseException]],
    exc_val: Optional[BaseException],
    exc_tb: Optional[TracebackType],
) -> None:
    """Deletes remote self.origin and creates a remote named origin with an url."""
    self.repo.delete_remote(self.origin)
    self.repo.create_remote("origin", self.restore_url)

__init__(repo, temp_url, restore_url)

Inits a TempGitRepo.

Parameters:

Name Type Description Default
repo Repo

Git repository

required
temp_url str

Temp url

required
restore_url str

Restore url

required
Source code in ssb_project_cli/ssb_project/create/temp_git_repo.py
13
14
15
16
17
18
19
20
21
22
23
def __init__(self, repo: Repo, temp_url: str, restore_url: str) -> None:
    """Inits a TempGitRepo.

    Args:
        repo: Git repository
        temp_url: Temp url
        restore_url: Restore url
    """
    self.repo = repo
    self.temp_url = temp_url
    self.restore_url = restore_url