Beispiel #1
0
def clone(server_repo_path, local_repo_path):
    """
    Clones a repository on the server to a local directory.

    Args:
        server_repo_path(str): Suffix of URL for remote repo to clone
        local_repo_path(str): Name of module to clone

    Raises:
        :class:`~dls_ade.exceptions.VCSGitError`: Repository does not contain \
            <source>
        :class:`~dls_ade.exceptions.VCSGitError`: <module> already exists in \
            current directory

    """
    if not is_server_repo(server_repo_path):
        raise VCSGitError("Repository does not contain " + server_repo_path)
    elif os.path.isdir(local_repo_path):
        raise VCSGitError(local_repo_path + " already exists in current " "directory")

    pathf.remove_end_slash(server_repo_path)

    print(os.path.join(GIT_SSH_ROOT, server_repo_path))

    repo = git.Repo.clone_from(os.path.join(GIT_SSH_ROOT, server_repo_path), os.path.join("./", local_repo_path))

    return repo
Beispiel #2
0
def temp_clone(source):
    """
    Clones repo to /tmp directory and returns the relevant git.Repo object.

    Args:
        source(str): server repository path to clone

    Returns:
        :class:`~git.repo.base.Repo`: Repository instance

    """
    if not is_server_repo(source):
        raise VCSGitError("Repository does not contain " + source)

    pathf.remove_end_slash(source)

    tempdir = tempfile.mkdtemp()

    repo = git.Repo.clone_from(os.path.join(GIT_SSH_ROOT, source), tempdir)

    return repo
    def test_given_empty_string_then_return(self):
        test_string = ""

        new_string = path_functions.remove_end_slash(test_string)

        self.assertEqual(new_string, "")
    def test_given_path_no_slash_then_returned(self):
        path = "controls/area/module"

        new_path = path_functions.remove_end_slash(path)

        self.assertEqual(new_path, path)