diff --git a/cmd/flux/bootstrap_gitlab.go b/cmd/flux/bootstrap_gitlab.go index fb22972c..a57b9aa5 100644 --- a/cmd/flux/bootstrap_gitlab.go +++ b/cmd/flux/bootstrap_gitlab.go @@ -22,6 +22,7 @@ import ( "io/ioutil" "os" "regexp" + "strings" "time" "github.com/go-git/go-git/v5/plumbing/transport/http" @@ -144,6 +145,12 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error { Hostname: gitlabArgs.hostname, Token: glToken, } + // Workaround for: https://github.com/fluxcd/go-git-providers/issues/55 + if hostname := providerCfg.Hostname; hostname != glDefaultDomain && + !strings.HasPrefix(hostname, "https://") && + !strings.HasPrefix(hostname, "http://") { + providerCfg.Hostname = "https://" + providerCfg.Hostname + } providerClient, err := provider.BuildGitProvider(providerCfg) if err != nil { return err diff --git a/internal/bootstrap/bootstrap_provider.go b/internal/bootstrap/bootstrap_provider.go index a6a17d4e..34c94410 100644 --- a/internal/bootstrap/bootstrap_provider.go +++ b/internal/bootstrap/bootstrap_provider.go @@ -210,6 +210,10 @@ func (b *GitProviderBootstrapper) ReconcileRepository(ctx context.Context) error } cloneURL := repo.Repository().GetCloneURL(gitprovider.TransportType(b.bootstrapTransportType)) + // TODO(hidde): https://github.com/fluxcd/go-git-providers/issues/55 + if strings.HasPrefix(cloneURL, "https://https://") { + cloneURL = strings.TrimPrefix(cloneURL, "https://") + } WithRepositoryURL(cloneURL).applyGit(b.PlainGitBootstrapper) return err @@ -380,6 +384,10 @@ func (b *GitProviderBootstrapper) getRepository(ctx context.Context) (gitprovide // the hostname of the URL will be modified to this hostname. func (b *GitProviderBootstrapper) getCloneURL(repository gitprovider.UserRepository, transport gitprovider.TransportType) (string, error) { u := repository.Repository().GetCloneURL(transport) + // TODO(hidde): https://github.com/fluxcd/go-git-providers/issues/55 + if strings.HasPrefix(u, "https://https://") { + u = strings.TrimPrefix(u, "https://") + } var err error if transport == gitprovider.TransportTypeSSH && b.sshHostname != "" { if u, err = setHostname(u, b.sshHostname); err != nil {