def clone_repo(clone_url: str, tempdir: str) -> Path: """ Clone git repository from url. :param clone_url: url to clone from, it can also be a local path (directory) :param tempdir: temporary directory, where the git is cloned :return: directory with cloned repo or None """ # clone_url can be url as well as path to directory, try to get the last part (strip .git) reponame = FramboGit.strip_dot_git(clone_url.split("/")[-1]) cloned_dir = Path(tempdir) / reponame clone_success = True try: FramboGit.call_git_cmd( f"clone --recurse-submodules {clone_url} {str(cloned_dir)}") except CalledProcessError: # clone git repository w/o submodule. In case submodules does not exist clone_success = False if not clone_success: try: FramboGit.call_git_cmd(f"clone {clone_url} {str(cloned_dir)}") except CalledProcessError: raise return cloned_dir
def test_strip_dot_git(self, url, expected_result): """Test strip_dot_git().""" assert Git.strip_dot_git(url) == expected_result