forked from LaconicNetwork/kompose
Merge pull request #1958 from cortex3/main
improve error output of git commands
This commit is contained in:
commit
feb82f1e7e
@ -1,6 +1,7 @@
|
|||||||
package openshift
|
package openshift
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/pkg/errors"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -34,12 +35,16 @@ func GetImageTag(image string) string {
|
|||||||
func GetAbsBuildContext(context string) (string, error) {
|
func GetAbsBuildContext(context string) (string, error) {
|
||||||
cmd := exec.Command("git", "rev-parse", "--show-prefix")
|
cmd := exec.Command("git", "rev-parse", "--show-prefix")
|
||||||
cmd.Dir = context
|
cmd.Dir = context
|
||||||
out, err := cmd.Output()
|
var out strings.Builder
|
||||||
|
var stderr strings.Builder
|
||||||
|
cmd.Stdout = &out
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", errors.New(stderr.String())
|
||||||
}
|
}
|
||||||
//convert output of command to string
|
//convert output of command to string
|
||||||
contextDir := strings.Trim(string(out), "\n")
|
contextDir := strings.Trim(out.String(), "\n")
|
||||||
return contextDir, nil
|
return contextDir, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,11 +58,15 @@ func HasGitBinary() bool {
|
|||||||
func GetGitCurrentRemoteURL(composeFileDir string) (string, error) {
|
func GetGitCurrentRemoteURL(composeFileDir string) (string, error) {
|
||||||
cmd := exec.Command("git", "ls-remote", "--get-url")
|
cmd := exec.Command("git", "ls-remote", "--get-url")
|
||||||
cmd.Dir = composeFileDir
|
cmd.Dir = composeFileDir
|
||||||
out, err := cmd.Output()
|
var out strings.Builder
|
||||||
|
var stderr strings.Builder
|
||||||
|
cmd.Stdout = &out
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", errors.New(stderr.String())
|
||||||
}
|
}
|
||||||
url := strings.TrimRight(string(out), "\n")
|
url := strings.TrimRight(out.String(), "\n")
|
||||||
if !strings.HasSuffix(url, ".git") {
|
if !strings.HasSuffix(url, ".git") {
|
||||||
url += ".git"
|
url += ".git"
|
||||||
}
|
}
|
||||||
@ -68,9 +77,13 @@ func GetGitCurrentRemoteURL(composeFileDir string) (string, error) {
|
|||||||
func GetGitCurrentBranch(composeFileDir string) (string, error) {
|
func GetGitCurrentBranch(composeFileDir string) (string, error) {
|
||||||
cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
|
cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
|
||||||
cmd.Dir = composeFileDir
|
cmd.Dir = composeFileDir
|
||||||
out, err := cmd.Output()
|
var out strings.Builder
|
||||||
|
var stderr strings.Builder
|
||||||
|
cmd.Stdout = &out
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", errors.New(stderr.String())
|
||||||
}
|
}
|
||||||
return strings.TrimRight(string(out), "\n"), nil
|
return strings.TrimRight(out.String(), "\n"), nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user