@@ -141,13 +141,13 @@ def __fetch_file(self, fp, commit=False, skip=True):
141
141
sha1 = fp
142
142
fp = "objects/{}/{}" .format (fp [:2 ], fp [2 :])
143
143
dest = os .path .join (".git/" , fp )
144
+ if skip and os .path .exists (dest ):
145
+ self .logger .debug ("{} skipped" .format (fp ))
146
+ return
144
147
if commit :
145
148
self .logger .debug ("Fetching commit {}" .format (sha1 ))
146
149
else :
147
150
self .logger .debug ("Fetching file {}" .format (fp ))
148
- if skip and os .path .exists (dest ):
149
- self .logger .debug ("{} skipped" .format (fp ))
150
- return
151
151
# check if the file exists with a HEAD request
152
152
reqp = self ._parsed .path + "/.git/" + fp
153
153
self .head (reqp )
@@ -227,14 +227,23 @@ def __recover_source(self, sha1, fp):
227
227
self .__recover_source (sha1 , fp )
228
228
else :
229
229
self .logger .info ("Successfully recovered {}" .format (fp ))
230
-
230
+
231
+ def __valid_branch (self , branch ):
232
+ """
233
+ Validate if a given branch name exists.
234
+
235
+ :param branch: branch name
236
+ """
237
+ self .head (self ._parsed .path + "/.git/refs/heads/" + branch )
238
+ return self .response .status_code == 200
239
+
231
240
def checkout (self , branch = "main" ):
232
241
"""
233
242
Git respository file enumeration function.
234
243
235
244
:param branch: repository branch to be enumerated
236
245
"""
237
- if not self .__git_installed :
246
+ if not self .__git_installed or not self . __valid_branch ( branch ) :
238
247
return
239
248
# retrieve existing .git files and commits
240
249
self .__fetch_files (branch )
0 commit comments