From c11e5c1f99a1d55ee7a01289358346732214fab0 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Tue, 2 Mar 2021 16:42:38 +0000 Subject: [PATCH] Revert "Fix Git clone error when checking out reference" This reverts commit 63cfb5eac0c6a67db43b4bd35b1ea09b05c07214. --- app/tasks/importtasks.py | 4 ++-- app/utils/git.py | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/tasks/importtasks.py b/app/tasks/importtasks.py index 480c275c..29f335f3 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) as repo: + with clone_repo(urlstr, recursive=True) 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, branch) as repo: + with clone_repo(release.package.repo, ref=branch, recursive=True) 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 5371c7ec..7d800f95 100644 --- a/app/utils/git.py +++ b/app/utils/git.py @@ -40,13 +40,28 @@ def get_temp_dir(): # Throws `TaskError` on failure. # Caller is responsible for deleting returned directory. @contextlib.contextmanager -def clone_repo(urlstr, ref=None): +def clone_repo(urlstr, ref=None, recursive=False): gitDir = os.path.join(tempfile.gettempdir(), randomString(10)) + err = None try: gitUrl = generateGitURL(urlstr) - repo = git.Repo.clone_from(gitUrl, gitDir, b=ref, - progress=None, env=None, depth=1, recursive=True, kill_after_timeout=15) + 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) yield repo shutil.rmtree(gitDir)