From 63cfb5eac0c6a67db43b4bd35b1ea09b05c07214 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Mon, 1 Mar 2021 18:10:46 +0000 Subject: [PATCH] Fix Git clone error when checking out reference --- app/tasks/importtasks.py | 4 ++-- app/utils/git.py | 21 +++------------------ 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/app/tasks/importtasks.py b/app/tasks/importtasks.py index 29f335f3..480c275c 100644 --- a/app/tasks/importtasks.py +++ b/app/tasks/importtasks.py @@ -31,7 +31,7 @@ from ..logic.packages import do_edit_package, ALIASES @celery.task() def getMeta(urlstr, author): - with clone_repo(urlstr, recursive=True) as repo: + with clone_repo(urlstr) as repo: try: tree = build_tree(repo.working_tree_dir, author=author, repo=urlstr) except MinetestCheckError as err: @@ -162,7 +162,7 @@ def makeVCSRelease(self, id, branch): elif release.package is None: raise TaskError("No package attached to release") - with clone_repo(release.package.repo, ref=branch, recursive=True) as repo: + with clone_repo(release.package.repo, branch) as repo: postReleaseCheckUpdate(self, release, repo.working_tree_dir) filename = randomString(10) + ".zip" diff --git a/app/utils/git.py b/app/utils/git.py index 7d800f95..5371c7ec 100644 --- a/app/utils/git.py +++ b/app/utils/git.py @@ -40,28 +40,13 @@ def get_temp_dir(): # Throws `TaskError` on failure. # Caller is responsible for deleting returned directory. @contextlib.contextmanager -def clone_repo(urlstr, ref=None, recursive=False): +def clone_repo(urlstr, ref=None): gitDir = os.path.join(tempfile.gettempdir(), randomString(10)) - err = None try: gitUrl = generateGitURL(urlstr) - print("Cloning from " + gitUrl) - - if ref is None: - repo = git.Repo.clone_from(gitUrl, gitDir, - progress=None, env=None, depth=1, recursive=recursive, kill_after_timeout=15) - else: - assert ref != "" - - repo = git.Repo.init(gitDir) - origin = repo.create_remote("origin", url=gitUrl) - assert origin.exists() - origin.fetch() - repo.git.checkout(ref) - - for submodule in repo.submodules: - submodule.update(init=True) + repo = git.Repo.clone_from(gitUrl, gitDir, b=ref, + progress=None, env=None, depth=1, recursive=True, kill_after_timeout=15) yield repo shutil.rmtree(gitDir)