diff --git a/runtime/default.go b/runtime/default.go index 5b85a3a2..2e36b3b6 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -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 } diff --git a/runtime/local/git/git.go b/runtime/local/git/git.go index c23a8080..956f02e7 100644 --- a/runtime/local/git/git.go +++ b/runtime/local/git/git.go @@ -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 }