Skip to content

Commit 371551d

Browse files
committed
Safely convert repo URL to https schema if URL is a public SCM service (github/butbucket), supporting all schemas.
This allows anonymous cloning of public repos without having to have ssh keys and associated accounts at github/bitbucket/etc. Without this anonymous users will get clone errors with ssh repository links even if the repository is public. See hhttps://help.github.com/articles/which-remote-url-should-i-use/
1 parent 4ea6eb7 commit 371551d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

mbed/mbed.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@
125125
# mbed SDK tools needed for programs based on mbed SDK library
126126
mbed_sdk_tools_url = 'https://mbed.org/users/mbed_official/code/mbed-sdk-tools'
127127

128+
# a list of public SCM service (github/butbucket) which support http, https and ssh schemas
129+
public_repo_services = ['bitbucket.org', 'github.com', 'gitlab.com']
130+
131+
128132
# verbose logging
129133
verbose = False
130134
very_verbose = False
@@ -1249,6 +1253,13 @@ def write(self):
12491253
#print self.name, 'unmodified'
12501254
return
12511255

1256+
if up.hostname in public_repo_services:
1257+
# Safely convert repo URL to https schema if this is a public SCM service (github/butbucket), supporting all schemas.
1258+
# This allows anonymous cloning of public repos without having to have ssh keys and associated accounts at github/bitbucket/etc.
1259+
# Without this anonymous users will get clone errors with ssh repository links even if the repository is public.
1260+
# See hhttps://help.github.com/articles/which-remote-url-should-i-use/
1261+
url = formaturl(url, 'https')
1262+
12521263
ref = url.rstrip('/') + '/' + (('' if self.is_build else '#') + self.rev if self.rev else '')
12531264
action("Updating reference \"%s\" -> \"%s\"" % (relpath(cwd_root, self.path) if cwd_root != self.path else self.name, ref))
12541265
with open(self.lib, 'wb') as f:
@@ -1720,7 +1731,7 @@ def formaturl(url, format="default"):
17201731
else:
17211732
m = re.match(regex_repo_url, url)
17221733
if m and m.group(1) == '': # no protocol specified, probably ssh string like "[email protected]:ARMmbed/mbed-os.git"
1723-
url = 'ssh://%s%s%s/%s.git' % (m.group(2) or 'git@', m.group(6), m.group(7), m.group(8)) # convert to common ssh URL-like format
1734+
url = 'ssh://%s%s%s/%s.git' % (m.group(2) or 'git@', m.group(6), m.group(7) or '', m.group(8)) # convert to common ssh URL-like format
17241735
m = re.match(regex_repo_url, url)
17251736

17261737
if m:

0 commit comments

Comments
 (0)