diff --git a/pkg/utils/gitrepo.go b/pkg/utils/gitrepo.go index c69a0f8d8..107ed8ab2 100644 --- a/pkg/utils/gitrepo.go +++ b/pkg/utils/gitrepo.go @@ -182,7 +182,22 @@ func getConnectionOptions(cloneOptions *GitCloneOption, primary bool) (connectio options := &git.CloneOptions{ URL: channelConnOptions.RepoURL, + SingleBranch: true, RecurseSubmodules: git.DefaultSubmoduleRecursionDepth, + ReferenceName: cloneOptions.Branch, + } + + // The destination directory needs to be created here + err = os.RemoveAll(cloneOptions.DestDir) + + if err != nil { + klog.Warning(err, "Failed to remove directory ", cloneOptions.DestDir) + } + + err = os.MkdirAll(cloneOptions.DestDir, os.ModePerm) + + if err != nil { + return nil, err } // If branch name is provided, clone the specified branch only. @@ -238,18 +253,6 @@ func getConnectionOptions(cloneOptions *GitCloneOption, primary bool) (connectio } } - err = os.RemoveAll(cloneOptions.DestDir) - - if err != nil { - klog.Warning(err, "Failed to remove directory ", cloneOptions.DestDir) - } - - err = os.MkdirAll(cloneOptions.DestDir, os.ModePerm) - - if err != nil { - return nil, err - } - return options, nil }