def get_project(name: str, directory: str = '') -> None: """Clone a project from a GitHub name or git url. Put it in dir if this argument is given. A GitHub name without / will be considered as a leanprover-community project. If the name ends with ':foo' then foo will be interpreted as a branch name, and that branch will be checked out.""" # check whether we can ssh into GitHub try: assert PARAMIKO_OK client = paramiko.client.SSHClient() client.set_missing_host_key_policy(paramiko.client.AutoAddPolicy()) client.connect('github.com', username='******') client.close() ssh = True except (AssertionError, AuthenticationException, SSHException): ssh = False name, url, branch = parse_project_name(name, ssh) if branch: name = name + '_' + branch directory = directory or name if directory and Path(directory).exists(): raise FileExistsError('Directory ' + directory + ' already exists') try: LeanProject.from_git_url(url, directory, branch, cache_url, force_download) except GitCommandError as err: handle_exception(err, 'Git command failed')
def get_project(name: str, new_branch: bool, directory: str = '') -> None: """Clone a project from a GitHub name or git url. Put it in dir if this argument is given. A GitHub name without / will be considered as a leanprover-community project. If the name ends with ':foo' then foo will be interpreted as a branch name, and that branch will be checked out. This will fail if the branch does not exist. If you want to create a new branch, pass the `-b` option.""" original_name = name name, url, branch, is_url = parse_project_name(original_name) if branch: name = name + '_' + branch directory = directory or name if directory and Path(directory).exists(): raise FileExistsError('Directory ' + directory + ' already exists') try: LeanProject.from_git_url(url, directory, branch, new_branch, cache_url, force_download) except GitCommandError as err: # if full url is provided, do not retry with HTTPS if not is_url: log.info('Error cloning via SSH, trying HTTPS...') try: name, url, branch, is_url = parse_project_name(original_name, ssh=False) LeanProject.from_git_url(url, directory, branch, new_branch, cache_url, force_download) except GitCommandError as e: handle_exception(e, e.stderr) else: handle_exception(err, err.stderr)