Skip to content

Commit

Permalink
feat: improve git clone mecanism
Browse files Browse the repository at this point in the history
Signed-off-by: gabriel-farache <gfarache@redhat.com>
  • Loading branch information
gabriel-farache committed Jul 5, 2024
1 parent 72ceb7b commit 248aa82
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion common/vcs/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 248aa82

Please sign in to comment.