Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/fosslight_util/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ def cli_download_and_extract(link: str, target_dir: str, log_dir: str, checkout_
is_rubygems = src_info.get("rubygems", False)

# General download (git clone, wget)
success_git, msg, oss_name, oss_version = download_git_clone(link, target_dir, checkout_to,
tag, branch, ssh_key, id, git_token)
success_git, msg, oss_name, oss_version = download_git_clone(link, target_dir,
checkout_to,
tag, branch,
ssh_key, id, git_token)
link = change_ssh_link_to_https(link)
if (not is_rubygems) and (not success_git):
if os.path.isfile(target_dir):
Expand Down Expand Up @@ -205,27 +207,22 @@ def get_github_token(git_url):
def download_git_repository(refs_to_checkout, git_url, target_dir, tag):
success = False
oss_version = ""
clone_default_branch_flag = False

logger.info(f"Download git url :{git_url}")
if refs_to_checkout:
try:
# gitPython uses the branch argument the same whether you check out to a branch or a tag.
repo = Repo.clone_from(git_url, target_dir, branch=refs_to_checkout)
success = True
oss_version = refs_to_checkout
except GitCommandError as error:
logger.debug(f"Git checkout error:{error}")
success = False

if not success:
repo = Repo.clone_from(git_url, target_dir)
clone_default_branch_flag = True
success = True

if refs_to_checkout != tag or clone_default_branch_flag:
oss_version = repo.active_branch.name
else:
oss_version = repo.git.describe('--tags')
return success, oss_version


Expand Down
4 changes: 2 additions & 2 deletions tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_download_from_github():


@pytest.mark.parametrize("git_url",
["git://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git;protocol=git;branch=ci-test",
["git://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git;protocol=git;branch=hash-stat2",
"git://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git;protocol=git;tag=v32"])
def test_download_from_github_with_branch_or_tag(git_url):
# given
Expand Down Expand Up @@ -62,7 +62,7 @@ def test_download_git_clone_with_branch():
# given
git_url = "git://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git"
target_dir = os.path.join(constants.TEST_RESULT_DIR, "download/example")
branch_name = "ci-test"
branch_name = "hash-stat2"

# when
success, _, oss_name, oss_version = download_git_clone(git_url, target_dir, "", "", branch_name)
Expand Down