From 9668072f9135c9b91dc2249844f1a081d0b838ea Mon Sep 17 00:00:00 2001 From: Roke Jung Date: Wed, 6 Jul 2022 10:43:10 -0400 Subject: [PATCH] fix Git SSH known hosts (#779) Signed-off-by: Roke Jung --- pkg/utils/gitrepo.go | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) 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 }