1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00

Don't ignore errors from checkout source code (#1584)

Don't check out code for builtin services.
This commit is contained in:
Janos Dobronszki 2020-04-28 10:51:39 +02:00 committed by GitHub
parent 8148e0a0f8
commit b875868a39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 8 deletions

View File

@ -55,11 +55,17 @@ func NewRuntime(opts ...Option) Runtime {
// @todo move this to runtime default
func (r *runtime) checkoutSourceIfNeeded(s *Service) error {
// Runtime service like config have no source.
// Skip checkout in that case
if len(s.Source) == 0 {
return nil
}
source, err := git.ParseSourceLocal("", s.Source)
if err != nil {
return err
}
source.Ref = s.Version
err = git.CheckoutSource(os.TempDir(), source)
if err != nil {
return err
@ -209,7 +215,10 @@ func serviceKey(s *Service) string {
// Create creates a new service which is then started by runtime
func (r *runtime) Create(s *Service, opts ...CreateOption) error {
r.checkoutSourceIfNeeded(s)
err := r.checkoutSourceIfNeeded(s)
if err != nil {
return err
}
r.Lock()
defer r.Unlock()
@ -389,14 +398,17 @@ func (r *runtime) Read(opts ...ReadOption) ([]*Service, error) {
// Update attemps to update the service
func (r *runtime) Update(s *Service, opts ...UpdateOption) error {
r.checkoutSourceIfNeeded(s)
err := r.checkoutSourceIfNeeded(s)
if err != nil {
return err
}
r.Lock()
service, ok := r.services[serviceKey(s)]
r.Unlock()
if !ok {
return errors.New("Service not found")
}
err := service.Stop()
err = service.Stop()
if err != nil {
return err
}

View File

@ -1,6 +1,7 @@
package git
import (
"errors"
"fmt"
"os"
"os/exec"
@ -105,7 +106,7 @@ type binaryGitter struct {
}
func (g binaryGitter) Clone(repo string) error {
fold := filepath.Join(g.folder, dirifyRepo(repo))
fold := filepath.Join(g.folder, dirifyRepo(repo), ".git")
exists, err := pathExists(fold)
if err != nil {
return err
@ -113,6 +114,7 @@ func (g binaryGitter) Clone(repo string) error {
if exists {
return nil
}
fold = filepath.Join(g.folder, dirifyRepo(repo))
cmd := exec.Command("git", "clone", repo, ".")
err = os.MkdirAll(fold, 0777)
@ -130,9 +132,9 @@ func (g binaryGitter) Clone(repo string) error {
func (g binaryGitter) FetchAll(repo string) error {
cmd := exec.Command("git", "fetch", "--all")
cmd.Dir = filepath.Join(g.folder, dirifyRepo(repo))
_, err := cmd.Output()
outp, err := cmd.CombinedOutput()
if err != nil {
return err
return errors.New(string(outp))
}
return err
}
@ -143,9 +145,9 @@ func (g binaryGitter) Checkout(repo, branchOrCommit string) error {
}
cmd := exec.Command("git", "checkout", "-f", branchOrCommit)
cmd.Dir = filepath.Join(g.folder, dirifyRepo(repo))
_, err := cmd.Output()
outp, err := cmd.CombinedOutput()
if err != nil {
return err
return errors.New(string(outp))
}
return nil
}