From 1de006d741a6da2fe218e415462888e3e88f7f5b Mon Sep 17 00:00:00 2001 From: Michael McLoughlin Date: Sun, 7 Nov 2021 16:30:50 -0800 Subject: [PATCH] tests/thirdparty: use shallow clone (#224) When trying to add a test case from the standard library, cloning golang/go was taking forever. This PR switches to a shallow clone. --- tests/thirdparty/packages_test.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/thirdparty/packages_test.go b/tests/thirdparty/packages_test.go index 3f434195..8e68efeb 100644 --- a/tests/thirdparty/packages_test.go +++ b/tests/thirdparty/packages_test.go @@ -71,17 +71,18 @@ func (t *PackageTest) Run() { // checkout the code at the specified version. func (t *PackageTest) checkout() { - // Clone repo. - dst := filepath.Join(t.WorkDir, t.Name()) - test.Exec(t.T, "git", "clone", "--quiet", t.Repository.CloneURL(), dst) - t.repopath = dst - - // Checkout specific version. + // Determine the version we want to checkout. + version := t.Version if t.Latest { - t.Log("using latest version") - return + version = t.DefaultBranch } - test.Exec(t.T, "git", "-C", t.repopath, "checkout", "--quiet", t.Version) + + // Clone. Use a shallow clone to speed up large repositories. + t.repopath = filepath.Join(t.WorkDir, t.Name()) + test.Exec(t.T, "git", "init", t.repopath) + test.Exec(t.T, "git", "-C", t.repopath, "remote", "add", "origin", t.Repository.CloneURL()) + test.Exec(t.T, "git", "-C", t.repopath, "fetch", "--depth=1", "origin", version) + test.Exec(t.T, "git", "-C", t.repopath, "checkout", "FETCH_HEAD") } func (t *PackageTest) steps() {