1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-03-17 21:07:54 +02:00

fix(cmd/new): print exception to console (#1227)

* fix(cmd/new): print exception to console

* using git command to replace judgment text
This commit is contained in:
包子 2021-07-21 22:44:11 +08:00 committed by GitHub
parent 0e70bddaa9
commit 1a0a1b8a89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}