diff --git a/clustertool/pkg/initfiles/initfiles.go b/clustertool/pkg/initfiles/initfiles.go index 4ebb005ecb81..d8b0b10c7c9c 100644 --- a/clustertool/pkg/initfiles/initfiles.go +++ b/clustertool/pkg/initfiles/initfiles.go @@ -116,15 +116,20 @@ func FormatGitURL(input string) string { // Remove "https://" prefix if present input = strings.TrimPrefix(input, "https://") + if !strings.HasPrefix(input, "ssh://") { + input = "ssh://" + input + } + // Ensure input starts with "ssh://git@" if !strings.HasPrefix(input, "ssh://git@") { // Prepend "ssh://git@" if neither "ssh://" nor "git@" is present - if !strings.HasPrefix(input, "ssh://") { - input = "ssh://" + input - } input = strings.Replace(input, "ssh://", "ssh://git@", 1) } + if strings.Contains(url, "git@git@") { + input = strings.Replace(input, "git@git@", "git@", 1) + } + // Compile a regex to match and replace the URL pattern re := regexp.MustCompile(`^ssh://git@([^:/]+)([:/])([\w-]+)/([\w-]+)\.git$`) matches := re.FindStringSubmatch(input)