Skip to content

Commit 8b2bb5e

Browse files
committed
Clones git directory to disk
1 parent 2a22cf2 commit 8b2bb5e

File tree

1 file changed

+18
-21
lines changed
  • pkg/patterns/addon/pkg/loaders

1 file changed

+18
-21
lines changed

pkg/patterns/addon/pkg/loaders/git.go

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ package loaders
33
import (
44
"context"
55
"fmt"
6-
"github.com/go-git/go-billy/v5/memfs"
76
"github.com/go-git/go-git/v5"
8-
"github.com/go-git/go-git/v5/storage/memory"
97
"io/ioutil"
8+
"os"
109
"sigs.k8s.io/controller-runtime/pkg/log"
1110
"sigs.k8s.io/yaml"
1211
"strings"
@@ -22,11 +21,8 @@ var _ Repository = &GitRepository{}
2221

2322
// NewGitRepository constructs an GitRepository
2423
func NewGitRepository(baseurl string) *GitRepository{
25-
baseurl, subDir := parseGitURL(baseurl)
26-
return &GitRepository{
27-
baseURL: baseurl,
28-
subDir: subDir,
29-
}
24+
repo := parseGitURL(baseurl)
25+
return &repo
3026
}
3127

3228
func (r *GitRepository) LoadChannel(ctx context.Context, name string) (*Channel, error){
@@ -91,22 +87,20 @@ func (r *GitRepository) LoadManifest(ctx context.Context, packageName string, id
9187
}
9288

9389
func (r *GitRepository) readURL(url string) ([]byte, error) {
94-
//// Adds support for sub directory
95-
//cloneUrl := r.baseURL
96-
//if strings.Contains(r.baseURL, ".git//") {
97-
// newURL := strings.Split(r.baseURL, ".git//")
98-
// cloneUrl = newURL[0] + ".git"
99-
// url = newURL[1] + "/" + url
100-
//}
101-
fs := memfs.New()
102-
_, err := git.Clone(memory.NewStorage(), fs, &git.CloneOptions{
103-
URL: r.baseURL,
90+
//fs := memfs.New()
91+
//_, err := git.Clone(memory.NewStorage(), fs, &git.CloneOptions{
92+
// // URL: r.baseURL,
93+
// //})
94+
repoDir := "/tmp/repo"
95+
fmt.Println(r.baseURL)
96+
_, err := git.PlainClone(repoDir, false, &git.CloneOptions{
97+
URL: r.baseURL,
10498
})
105-
if err != nil {
99+
if err != nil && err != git.ErrRepositoryAlreadyExists {
106100
return nil, err
107101
}
108102

109-
file, err := fs.Open(url)
103+
file, err := os.Open(repoDir + "/" + url)
110104
if err != nil{
111105
return nil, err
112106
}
@@ -119,7 +113,7 @@ func (r *GitRepository) readURL(url string) ([]byte, error) {
119113
return b, nil
120114
}
121115

122-
func parseGitURL(url string) (string, string){
116+
func parseGitURL(url string) GitRepository{
123117
// checks for git:: suffix
124118
var subdir string
125119
if strings.HasPrefix(url, "git::") {
@@ -133,5 +127,8 @@ func parseGitURL(url string) (string, string){
133127
subdir = newURL[1]
134128
}
135129

136-
return url, subdir
130+
return GitRepository{
131+
baseURL: url,
132+
subDir: subdir,
133+
}
137134
}

0 commit comments

Comments
 (0)