From 248aa82a6781f8c0bf382c38caef27dfc63598af Mon Sep 17 00:00:00 2001 From: gabriel-farache Date: Fri, 5 Jul 2024 17:18:45 +0200 Subject: [PATCH] feat: improve git clone mecanism Signed-off-by: gabriel-farache --- common/vcs/git.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/common/vcs/git.go b/common/vcs/git.go index 4e8fb4240..2c0f07c50 100644 --- a/common/vcs/git.go +++ b/common/vcs/git.go @@ -257,11 +257,21 @@ func (gvcsrepo *GitVCSRepo) Clone(cloneOptions VCSCloneOptions) (string, error) } gvcsrepo.GitRepository, err = git.Clone(limitStorer, repoDirWt, &cloneOpts) if err != nil { - logrus.Debugf("failed to clone the given branch '%s' . Will clone the entire repo and try again.", gvcsrepo.Branch) + logrus.Warningf("failed to clone the given branch '%s': %v . Will clone the entire repo and try again.", gvcsrepo.Branch, err) cloneOpts := git.CloneOptions{ URL: gvcsrepo.URL, Depth: commitDepth, } + logrus.Infof("Removing previous cloned repository folder and recreating storer: %q", repoPath) + + if err := os.RemoveAll(repoPath); err != nil { + return "", fmt.Errorf("failed to remove the files/directories at '%s' . error: %w", repoPath, err) + } + repoDirWt = osfs.New(repoPath) + dotGitDir, _ = repoDirWt.Chroot(git.GitDirName) + fStorer := filesystem.NewStorage(dotGitDir, cache.NewObjectLRUDefault()) + limitStorer := Limit(fStorer, cloneOptions.MaxSize) + gvcsrepo.GitRepository, err = git.Clone(limitStorer, repoDirWt, &cloneOpts) if err != nil { return "", fmt.Errorf("failed to perform clone operation using git. Error: %w", err)