From bbbd4037b41bef71abc3f82d2524b1e8bd5f90dc Mon Sep 17 00:00:00 2001 From: Ratnadeep Debnath Date: Fri, 2 Dec 2016 15:37:50 +0530 Subject: [PATCH] Update command to fetch current git remote for buildconfig. --- pkg/transformer/openshift/openshift.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/transformer/openshift/openshift.go b/pkg/transformer/openshift/openshift.go index dbdd9949..67ec982d 100644 --- a/pkg/transformer/openshift/openshift.go +++ b/pkg/transformer/openshift/openshift.go @@ -112,15 +112,19 @@ func getGitCurrentBranch(composeFileDir string) (string, error) { } // getGitRemoteForBranch gets git remote for a branch -func getGitRemoteForBranch(composeFileDir string, branch string) (string, error) { - cmd := exec.Command("sh", "-c", fmt.Sprintf("git branch -r | grep %s", branch)) +func getGitRemoteForCurrentBranch(composeFileDir string) (string, error) { + cmd := exec.Command("sh", "-c", "git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)") cmd.Dir = composeFileDir out, err := cmd.Output() if err != nil { return "", err } - return strings.Split(strings.Trim(string(out), "\n "), "/")[0], nil + output := strings.Trim(string(out), "\n ") + if output == "" { + return "", errors.New("Remote missing for current branch.") + } + return strings.Split(output, "/")[0], nil } // getComposeFileDir returns compose file directory @@ -361,7 +365,7 @@ func (o *OpenShift) Transform(komposeObject kobject.KomposeObject, opt kobject.C } if opt.BuildRepo == "" { var buildRemote string - buildRemote, err = getGitRemoteForBranch(composeFileDir, buildBranch) + buildRemote, err = getGitRemoteForCurrentBranch(composeFileDir) if err != nil { logrus.Fatalf("Buildconfig cannot be created because remote for current git branch couldn't be detected.") }