gitrepo: match against api types when creating git client

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
This commit is contained in:
Sanskar Jaiswal 2022-10-19 13:26:39 +05:30 committed by Paulo Gomes
parent d25ed0c8c4
commit 22e712b935
No known key found for this signature in database
GPG Key ID: 9995233870E99BEE
1 changed files with 5 additions and 2 deletions

View File

@ -768,10 +768,13 @@ func (r *GitRepositoryReconciler) gitCheckout(ctx context.Context,
var gitReader git.RepositoryReader
var err error
if obj.Spec.GitImplementation == libgit2.ClientName {
switch obj.Spec.GitImplementation {
case sourcev1.LibGit2Implementation:
gitReader, err = libgit2.NewClient(dir, authOpts)
} else {
case sourcev1.GoGitImplementation, "":
gitReader, err = gogit.NewClient(dir, authOpts)
default:
err = fmt.Errorf("invalid Git implementation: %s", obj.Spec.GitImplementation)
}
if err != nil {
// Do not return err as recovery without changes is impossible.