From 356f5f674be197259e917814c7c0aee530254d79 Mon Sep 17 00:00:00 2001 From: Matt Fields Date: Tue, 7 Jul 2020 16:43:11 -0400 Subject: [PATCH] Add logic for transforming gist repository urls to ssh --- github_backup/github_backup.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/github_backup/github_backup.py b/github_backup/github_backup.py index 178da62..839435b 100644 --- a/github_backup/github_backup.py +++ b/github_backup/github_backup.py @@ -419,7 +419,13 @@ def get_github_host(args): def get_github_repo_url(args, repository): if repository.get('is_gist'): - return repository['git_pull_url'] + if args.prefer_ssh: + # The git_pull_url value is always https for gists, so we need to transform it to ssh form + repo_url = re.sub('^https?:\/\/(.+)\/(.+)\.git$', r'git@\1:\2.git', repository['git_pull_url']) + repo_url = re.sub('^git@gist\.', 'git@', repo_url) # strip gist subdomain for better hostkey compatibility + else: + repo_url = repository['git_pull_url'] + return repo_url if args.prefer_ssh: return repository['ssh_url']