@@ -27,7 +27,6 @@ def clone_file(download_url, file_path):
2727 """
2828 Clones the file at the download_url to the file_path
2929 """
30- print ('Cloning file' , file_path )
3130 r = requests .get (download_url , stream = True )
3231 try :
3332 r .raise_for_status ()
@@ -38,14 +37,13 @@ def clone_file(download_url, file_path):
3837 for chunk in r .iter_content (chunk_size = 128 ):
3938 fd .write (chunk )
4039
41- def clone (base_url , path = None ):
40+ def clone (base_url , path = None , ref = None ):
4241 """
4342 Recursively clones the path
4443 """
45- print ('Cloning directory' , path )
4644 req_url = base_url if not path else os .path .join (base_url , path )
4745 # Get path metadata
48- r = requests .get (req_url )
46+ r = requests .get (req_url ) if not ref else requests . get ( req_url , params = { 'ref' : ref })
4947 try :
5048 r .raise_for_status ()
5149 except Exception as e :
@@ -60,10 +58,11 @@ def clone(base_url, path=None):
6058 for item in repo_data :
6159 if item ['type' ] == 'dir' :
6260 # Fetch dir recursively
63- clone (base_url , item ['path' ])
61+ clone (base_url , item ['path' ], ref )
6462 else :
6563 # Fetch the file
6664 clone_file (item ['download_url' ], item ['path' ])
65+ print ('Cloned' , item ['path' ])
6766
6867
6968###
@@ -77,12 +76,12 @@ def clone(base_url, path=None):
7776 normal_gh_url = re .sub (BASE_NORMALIZE_REGEX , '' , gh_url ).replace ('/tree' , '' )
7877 gh_url_comps = normal_gh_url .split ('/' )
7978 user , repo = gh_url_comps [:2 ]
80- branch = gh_url_comps [2 ]
79+ ref = gh_url_comps [2 ]
8180 path = os .path .join (* gh_url_comps [3 :])
8281else :
8382 exit_with_m ('Nothing to clone :(' )
8483
8584api_req_url = GH_REPO_CONTENTS_ENDPOINT .format (user , repo )
8685print ("Cloning into '%s'..." % path )
87- clone (api_req_url , path )
86+ clone (api_req_url , path , ref )
8887print ("done." )
0 commit comments