Skip to content

Commit 4bf81ec

Browse files
committed
Allows cloning subdirectories
1 parent 40c9650 commit 4bf81ec

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

pkg/patterns/addon/pkg/loaders/fs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func NewManifestLoader(channel string) (*ManifestLoader, error) {
4747
return &ManifestLoader{repo: repo}, nil
4848
}
4949

50-
if strings.Contains(channel, ".git//") || strings.HasSuffix(channel, ".git") {
50+
if strings.Contains(channel, "git//") || strings.Contains(channel, ".git") {
5151
repo := NewGitRepository(channel)
5252
return &ManifestLoader{repo: repo}, nil
5353
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package loaders
33
import (
44
"context"
55
"fmt"
6+
"github.com/go-git/go-billy/v5/memfs"
67
"github.com/go-git/go-git/v5"
78
"github.com/go-git/go-git/v5/storage/memory"
8-
"github.com/go-git/go-billy/v5/memfs"
99
"io/ioutil"
1010
"sigs.k8s.io/controller-runtime/pkg/log"
1111
"sigs.k8s.io/yaml"
12+
"strings"
1213
)
1314

1415
type GitRepository struct {
@@ -75,9 +76,16 @@ func (r *GitRepository) LoadManifest(ctx context.Context, packageName string, id
7576
}
7677

7778
func (r *GitRepository) readURL(url string) ([]byte, error) {
79+
// Adds support for sub directory
80+
cloneUrl := r.baseURL
81+
if strings.Contains(r.baseURL, ".git//") {
82+
newURL := strings.Split(r.baseURL, ".git//")
83+
cloneUrl = newURL[0] + ".git"
84+
url = newURL[1] + "/" + url
85+
}
7886
fs := memfs.New()
7987
_, err := git.Clone(memory.NewStorage(), fs, &git.CloneOptions{
80-
URL: r.baseURL,
88+
URL: cloneUrl,
8189
})
8290
if err != nil {
8391
return nil, err

0 commit comments

Comments
 (0)