semaphoreui/semaphore · error

invalid git url

Error message

invalid git url: %s

What it means

GetGitURL builds an authenticated HTTPS URL from a repository's GitURL. It only supports http/https remotes; when the URL does not start with 'http://' or 'https://', it panics with 'invalid git url: %s'. Callers include GetFullPath, Clone, GetLastRemoteCommitHash, GetRemoteBranches, prepareRun, and prepareRunTerraform.

Solutions

  1. Replace the repository's GitURL with an https:// URL, e.g. https://host/org/repo.git instead of git@host:org/repo.git
  2. Configure an access key/auth on the repository so the HTTPS URL can authenticate, instead of relying on SSH
  3. Validate the URL scheme (must match ^https?://) when creating the repository to fail early at input time

Example fix

// before
repo.GitURL = "git@github.com:org/repo.git"
// after
repo.GitURL = "https://github.com/org/repo.git"
Defensive patterns

Strategy: validation

Validate before calling

var httpRe = regexp.MustCompile(`^https?://`)
func validGitURL(u string) bool { return httpRe.MatchString(u) }
// reject repo creation/update when !validGitURL(repo.GitURL)

Try / catch

defer func() {
    if r := recover(); r != nil {
        if strings.Contains(fmt.Sprint(r), "invalid git url") {
            err = fmt.Errorf("repository must use an https URL: %v", r)
        } else {
            panic(r)
        }
    }
}()

Prevention

When it happens

Trigger: Creating/updating a repository whose GitURL uses ssh://, git@host:repo.git SCP-style syntax, or any non-http(s) scheme, then triggering any operation that needs the remote (clone, fetch last commit, list branches, run).

Common situations: Pasting an SSH clone URL from a git host into the repository settings; repositories configured before the project standardized on HTTPS; internal tooling defaulting to git:// schemes.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of semaphoreui/semaphore@1774ccb71a (2026-09-07). Data as JSON: /api/errors/3cd4834836581b97. Report an issue: GitHub.

Appendix: source

Thrown at db/Repository.go:104

		auth := ""
		switch r.SSHKey.Type {
		case AccessKeyLoginPassword:
			if r.SSHKey.LoginPassword.Login == "" {
				auth = r.SSHKey.LoginPassword.Password
			} else {
				auth = r.SSHKey.LoginPassword.Login + ":" + r.SSHKey.LoginPassword.Password
			}
		}
		if auth != "" {
			auth += "@"
		}

		re := regexp.MustCompile(`^(https?)://`)
		m := re.FindStringSubmatch(url)
		var protocol string

		if m == nil {
			panic(fmt.Errorf("invalid git url: %s", url))
		}

		protocol = m[1]

		url = protocol + "://" + auth + r.GitURL[len(protocol)+3:]
	}

	return url
}

func (r Repository) GetType() RepositoryType {
	if strings.HasPrefix(r.GitURL, "/") {
		return RepositoryLocal
	}

	if util.IsWindowsLocalRepositoryPath(r.GitURL) {
		return RepositoryLocal
	}

View on GitHub (pinned to 1774ccb71a)