From e93da2468c03c0860cbbe64416a2b0562185d117 Mon Sep 17 00:00:00 2001 From: Cluas Date: Thu, 15 Apr 2021 13:28:18 +0800 Subject: [PATCH] cmd: use structured path (#838) --- cmd/kratos/internal/base/repo.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/kratos/internal/base/repo.go b/cmd/kratos/internal/base/repo.go index ce54bf743..aeb8c2424 100644 --- a/cmd/kratos/internal/base/repo.go +++ b/cmd/kratos/internal/base/repo.go @@ -18,9 +18,11 @@ type Repo struct { // NewRepo new a repository manager. func NewRepo(url string) *Repo { + start := strings.Index(url, "//") + end := strings.LastIndex(url, "/") return &Repo{ url: url, - home: kratosHomeWithDir("repo"), + home: kratosHomeWithDir("repo/" + url[start+2:end]), } } @@ -31,8 +33,8 @@ func (r *Repo) Path() string { return path.Join(r.home, r.url[start+1:end]) } -// Pull fetchs the repository from remote url. -func (r *Repo) Pull(ctx context.Context, url string) error { +// Pull fetch the repository from remote url. +func (r *Repo) Pull(ctx context.Context) error { repo, err := git.PlainOpen(r.Path()) if err != nil { return err @@ -53,7 +55,7 @@ func (r *Repo) Pull(ctx context.Context, url string) error { // Clone clones the repository to cache path. func (r *Repo) Clone(ctx context.Context) error { if _, err := os.Stat(r.Path()); !os.IsNotExist(err) { - return r.Pull(ctx, r.url) + return r.Pull(ctx) } _, err := git.PlainCloneContext(ctx, r.Path(), false, &git.CloneOptions{ URL: r.url,