Skip to content

Commit f3ff998

Browse files
committed
Fixed issue in bots.utils.git
1 parent 948a94e commit f3ff998

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

pybots/bots/utils/git.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ def __fetch_file(self, fp, commit=False, skip=True):
141141
sha1 = fp
142142
fp = "objects/{}/{}".format(fp[:2], fp[2:])
143143
dest = os.path.join(".git/", fp)
144+
if skip and os.path.exists(dest):
145+
self.logger.debug("{} skipped".format(fp))
146+
return
144147
if commit:
145148
self.logger.debug("Fetching commit {}".format(sha1))
146149
else:
147150
self.logger.debug("Fetching file {}".format(fp))
148-
if skip and os.path.exists(dest):
149-
self.logger.debug("{} skipped".format(fp))
150-
return
151151
# check if the file exists with a HEAD request
152152
reqp = self._parsed.path + "/.git/" + fp
153153
self.head(reqp)
@@ -227,14 +227,23 @@ def __recover_source(self, sha1, fp):
227227
self.__recover_source(sha1, fp)
228228
else:
229229
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+
231240
def checkout(self, branch="main"):
232241
"""
233242
Git respository file enumeration function.
234243
235244
:param branch: repository branch to be enumerated
236245
"""
237-
if not self.__git_installed:
246+
if not self.__git_installed or not self.__valid_branch(branch):
238247
return
239248
# retrieve existing .git files and commits
240249
self.__fetch_files(branch)

pybots/core/ssocket.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ def read_until(self, pattern, disp=None, limit=10):
241241
return ""
242242
pattern = pattern.search(self.buffer).group()
243243
else:
244-
print(pattern)
245244
self.logger.error("Incorrect pattern")
246245
return
247246
try:

0 commit comments

Comments
 (0)