in pkg/git/git.go [387:430]
func (gp *GitProvider) CloneRepositoryBySsh(ctx context.Context, key, user, repoUrl, destination string, port int32) error {
l := ctrl.LoggerFrom(ctx)
l.Info("Start cloning", logRepositoryKey, repoUrl)
keyPath, err := InitAuth(key, user)
if err != nil {
return err
}
defer func() {
if err = os.Remove(keyPath); err != nil {
l.Error(err, errRemoveSHHKeyFile)
}
}()
cloneCMD := exec.Command(gitCMD, "clone", "--mirror", "--depth", "1", repoUrl, destination)
cloneCMD.Env = []string{fmt.Sprintf(`GIT_SSH_COMMAND=ssh -i %s -l %s -o StrictHostKeyChecking=no -p %d`,
keyPath, user, port), gitSshVariantEnv}
bytes, err := cloneCMD.CombinedOutput()
if err != nil {
return fmt.Errorf("failed to clone repo by ssh, err: %s: %w", string(bytes), err)
}
fetchCMD := exec.Command(gitCMD, gitDirArg, destination, getFetchArg, gitUnshallowArg)
fetchCMD.Env = cloneCMD.Env
bts, err := fetchCMD.CombinedOutput()
if err != nil {
return fmt.Errorf("failed to fetch unshallow repo: %s: %w", string(bts), err)
}
l.Info("Result of `git fetch unshallow` command", logOutKey, string(bts))
err = gp.BareToNormal(destination)
if err != nil {
return fmt.Errorf("failed to covert bare repo to normal: %w", err)
}
l.Info("End cloning", logRepositoryKey, repoUrl)
return nil
}