In buildconfig, get git's current remote URL instead of current branch's remote.

This commit is contained in:
Ratnadeep Debnath 2016-12-02 17:23:06 +05:30
parent bbbd4037b4
commit f0165d209f

View File

@ -83,9 +83,9 @@ func hasGitBinary() bool {
return err == nil
}
// getGitRemote gets git remote URI for the current git repo
func getGitRemote(composeFileDir string, remote string) (string, error) {
cmd := exec.Command("git", "ls-remote", "--get-url", remote)
// getGitCurrentRemoteUrl gets current git remote URI for the current git repo
func getGitCurrentRemoteUrl(composeFileDir string) (string, error) {
cmd := exec.Command("git", "ls-remote", "--get-url")
cmd.Dir = composeFileDir
out, err := cmd.Output()
if err != nil {
@ -111,22 +111,6 @@ func getGitCurrentBranch(composeFileDir string) (string, error) {
return strings.TrimRight(string(out), "\n"), nil
}
// getGitRemoteForBranch gets git remote for a 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
}
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
func getComposeFileDir(inputFile string) (string, error) {
if strings.Index(inputFile, "/") != 0 {
@ -364,12 +348,10 @@ func (o *OpenShift) Transform(komposeObject kobject.KomposeObject, opt kobject.C
}
}
if opt.BuildRepo == "" {
var buildRemote string
buildRemote, err = getGitRemoteForCurrentBranch(composeFileDir)
if err != nil {
logrus.Fatalf("Buildconfig cannot be created because remote for current git branch couldn't be detected.")
}
buildRepo, err = getGitRemote(composeFileDir, buildRemote)
buildRepo, err = getGitCurrentRemoteUrl(composeFileDir)
if err != nil {
logrus.Fatalf("Buildconfig cannot be created because git remote origin repo couldn't be detected.")
}