Skip to content

Commit 2219e29

Browse files
committed
Print branch name if checkout fails
1 parent 7c99357 commit 2219e29

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

src/fosslight_util/download.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ def cli_download_and_extract(link: str, target_dir: str, log_dir: str, checkout_
102102
msg_wget = ""
103103
oss_name = ""
104104
oss_version = ""
105-
clone_default_branch_flag = False
106105
log_file_name = "fosslight_download_" + \
107106
datetime.now().strftime('%Y%m%d_%H-%M-%S')+".txt"
108107
logger, log_item = init_log(os.path.join(log_dir, log_file_name))
@@ -124,10 +123,10 @@ def cli_download_and_extract(link: str, target_dir: str, log_dir: str, checkout_
124123
is_rubygems = src_info.get("rubygems", False)
125124

126125
# General download (git clone, wget)
127-
success_git, msg, oss_name, oss_version, clone_default_branch_flag = download_git_clone(link, target_dir,
128-
checkout_to,
129-
tag, branch,
130-
ssh_key, id, git_token)
126+
success_git, msg, oss_name, oss_version = download_git_clone(link, target_dir,
127+
checkout_to,
128+
tag, branch,
129+
ssh_key, id, git_token)
131130
link = change_ssh_link_to_https(link)
132131
if (not is_rubygems) and (not success_git):
133132
if os.path.isfile(target_dir):
@@ -154,7 +153,7 @@ def cli_download_and_extract(link: str, target_dir: str, log_dir: str, checkout_
154153
msg = str(error)
155154

156155
logger.info(f"\n* FOSSLight Downloader - Result: {success} ({msg})")
157-
return success, msg, oss_name, oss_version, clone_default_branch_flag
156+
return success, msg, oss_name, oss_version
158157

159158

160159
def get_ref_to_checkout(checkout_to, ref_list):
@@ -216,6 +215,7 @@ def download_git_repository(refs_to_checkout, git_url, target_dir, tag):
216215
# gitPython uses the branch argument the same whether you check out to a branch or a tag.
217216
repo = Repo.clone_from(git_url, target_dir, branch=refs_to_checkout)
218217
success = True
218+
oss_version = refs_to_checkout
219219
except GitCommandError as error:
220220
logger.debug(f"Git checkout error:{error}")
221221
success = False
@@ -224,15 +224,8 @@ def download_git_repository(refs_to_checkout, git_url, target_dir, tag):
224224
repo = Repo.clone_from(git_url, target_dir)
225225
clone_default_branch_flag = True
226226
success = True
227-
try:
228-
if clone_default_branch_flag:
229-
oss_version = repo.active_branch.name
230-
else:
231-
oss_version = repo.git.describe('--tags')
232-
except Exception as error:
233-
logger.debug(f"Get tag/branch error:{error}")
234-
235-
return success, oss_version, clone_default_branch_flag
227+
oss_version = repo.active_branch.name
228+
return success, oss_version
236229

237230

238231
def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch="", ssh_key="", id="", git_token=""):
@@ -260,7 +253,7 @@ def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch="", s
260253
logger.info(f"Download git with ssh_key:{git_url}")
261254
git_ssh_cmd = f'ssh -i {ssh_key}'
262255
with Git().custom_environment(GIT_SSH_COMMAND=git_ssh_cmd):
263-
success, oss_version, clone_default_branch_flag = download_git_repository(refs_to_checkout, git_url, target_dir, tag)
256+
success, oss_version = download_git_repository(refs_to_checkout, git_url, target_dir, tag)
264257
else:
265258
if id and git_token:
266259
try:
@@ -270,7 +263,7 @@ def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch="", s
270263
git_url = git_url.replace(protocol, f"{protocol}{id}:{git_token}@")
271264
except Exception as error:
272265
logger.info(f"Failed to insert id, token to git url:{error}")
273-
success, oss_version, clone_default_branch_flag = download_git_repository(refs_to_checkout, git_url, target_dir, tag)
266+
success, oss_version = download_git_repository(refs_to_checkout, git_url, target_dir, tag)
274267

275268
logger.info(f"git checkout: {oss_version}")
276269
refs_to_checkout = oss_version
@@ -284,7 +277,7 @@ def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch="", s
284277
logger.warning(f"git clone - failed: {error}")
285278
msg = str(error)
286279

287-
return success, msg, oss_name, refs_to_checkout, clone_default_branch_flag
280+
return success, msg, oss_name, refs_to_checkout
288281

289282

290283
def download_wget(link, target_dir, compressed_only):

0 commit comments

Comments
 (0)