mirror of
				https://github.com/go-kratos/kratos.git
				synced 2025-10-30 23:47:59 +02:00 
			
		
		
		
	cmd: use structured path (#838)
This commit is contained in:
		| @@ -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, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user