From 1a0a1b8a892b94efda4b2e09ec446ef974948a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8C=85=E5=AD=90?= Date: Wed, 21 Jul 2021 22:44:11 +0800 Subject: [PATCH] fix(cmd/new): print exception to console (#1227) * fix(cmd/new): print exception to console * using git command to replace judgment text --- cmd/kratos/internal/base/repo.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/kratos/internal/base/repo.go b/cmd/kratos/internal/base/repo.go index c00ba6678..07a067446 100644 --- a/cmd/kratos/internal/base/repo.go +++ b/cmd/kratos/internal/base/repo.go @@ -1,7 +1,6 @@ package base import ( - "bytes" "context" "os" "os/exec" @@ -51,15 +50,17 @@ func (r *Repo) Path() string { // Pull fetch the repository from remote url. func (r *Repo) Pull(ctx context.Context) error { - cmd := exec.Command("git", "pull") + cmd := exec.Command("git", "symbolic-ref", "HEAD") cmd.Dir = r.Path() - var out bytes.Buffer - cmd.Stderr = &out - cmd.Stdout = os.Stdout err := cmd.Run() - if strings.Contains(out.String(), "You are not currently on a branch.") { + if err != nil { return nil } + cmd = exec.Command("git", "pull") + cmd.Dir = r.Path() + cmd.Stderr = os.Stderr + cmd.Stdout = os.Stdout + err = cmd.Run() return err }