mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-24 03:46:37 +02:00
cmd: use structured path (#838)
This commit is contained in:
parent
089cf9d0cb
commit
e93da2468c
@ -18,9 +18,11 @@ type Repo struct {
|
|||||||
|
|
||||||
// NewRepo new a repository manager.
|
// NewRepo new a repository manager.
|
||||||
func NewRepo(url string) *Repo {
|
func NewRepo(url string) *Repo {
|
||||||
|
start := strings.Index(url, "//")
|
||||||
|
end := strings.LastIndex(url, "/")
|
||||||
return &Repo{
|
return &Repo{
|
||||||
url: url,
|
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])
|
return path.Join(r.home, r.url[start+1:end])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pull fetchs the repository from remote url.
|
// Pull fetch the repository from remote url.
|
||||||
func (r *Repo) Pull(ctx context.Context, url string) error {
|
func (r *Repo) Pull(ctx context.Context) error {
|
||||||
repo, err := git.PlainOpen(r.Path())
|
repo, err := git.PlainOpen(r.Path())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -53,7 +55,7 @@ func (r *Repo) Pull(ctx context.Context, url string) error {
|
|||||||
// Clone clones the repository to cache path.
|
// Clone clones the repository to cache path.
|
||||||
func (r *Repo) Clone(ctx context.Context) error {
|
func (r *Repo) Clone(ctx context.Context) error {
|
||||||
if _, err := os.Stat(r.Path()); !os.IsNotExist(err) {
|
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{
|
_, err := git.PlainCloneContext(ctx, r.Path(), false, &git.CloneOptions{
|
||||||
URL: r.url,
|
URL: r.url,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user