@@ -3,10 +3,9 @@ package loaders
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "github.com/go-git/go-billy/v5/memfs"
7
6
"github.com/go-git/go-git/v5"
8
- "github.com/go-git/go-git/v5/storage/memory"
9
7
"io/ioutil"
8
+ "os"
10
9
"sigs.k8s.io/controller-runtime/pkg/log"
11
10
"sigs.k8s.io/yaml"
12
11
"strings"
@@ -22,11 +21,8 @@ var _ Repository = &GitRepository{}
22
21
23
22
// NewGitRepository constructs an GitRepository
24
23
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
30
26
}
31
27
32
28
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
91
87
}
92
88
93
89
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 ,
104
98
})
105
- if err != nil {
99
+ if err != nil && err != git . ErrRepositoryAlreadyExists {
106
100
return nil , err
107
101
}
108
102
109
- file , err := fs .Open (url )
103
+ file , err := os .Open (repoDir + "/" + url )
110
104
if err != nil {
111
105
return nil , err
112
106
}
@@ -119,7 +113,7 @@ func (r *GitRepository) readURL(url string) ([]byte, error) {
119
113
return b , nil
120
114
}
121
115
122
- func parseGitURL (url string ) ( string , string ) {
116
+ func parseGitURL (url string ) GitRepository {
123
117
// checks for git:: suffix
124
118
var subdir string
125
119
if strings .HasPrefix (url , "git::" ) {
@@ -133,5 +127,8 @@ func parseGitURL(url string) (string, string){
133
127
subdir = newURL [1 ]
134
128
}
135
129
136
- return url , subdir
130
+ return GitRepository {
131
+ baseURL : url ,
132
+ subDir : subdir ,
133
+ }
137
134
}
0 commit comments