From 0b842d7569f90447b58e1ad028fe280482d7243d Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Thu, 27 Apr 2023 10:46:30 -0400 Subject: [PATCH] fix(ui): empty repo clone command --- ui/common/utils.go | 15 ++++++++++----- ui/pages/repo/empty.go | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ui/common/utils.go b/ui/common/utils.go index 97d498cb6..6ed9b714d 100644 --- a/ui/common/utils.go +++ b/ui/common/utils.go @@ -16,8 +16,8 @@ func TruncateString(s string, max int) string { return truncate.StringWithTail(s, uint(max), "…") } -// CloneCmd returns the URL of the repository. -func CloneCmd(publicURL, name string) string { +// RepoURL returns the URL of the repository. +func RepoURL(publicURL, name string) string { name = utils.SanitizeRepo(name) + ".git" url, err := url.Parse(publicURL) if err == nil { @@ -25,12 +25,17 @@ func CloneCmd(publicURL, name string) string { case "ssh": port := url.Port() if port == "" || port == "22" { - return fmt.Sprintf("git clone git@%s:%s", url.Hostname(), name) + return fmt.Sprintf("git@%s:%s", url.Hostname(), name) } else { - return fmt.Sprintf("git clone ssh://%s:%s/%s", url.Hostname(), url.Port(), name) + return fmt.Sprintf("ssh://%s:%s/%s", url.Hostname(), url.Port(), name) } } } - return fmt.Sprintf("git clone %s/%s", publicURL, name) + return fmt.Sprintf("%s/%s", publicURL, name) +} + +// CloneCmd returns the URL of the repository. +func CloneCmd(publicURL, name string) string { + return fmt.Sprintf("git clone %s", RepoURL(publicURL, name)) } diff --git a/ui/pages/repo/empty.go b/ui/pages/repo/empty.go index 1e62e8f86..fe3921d9c 100644 --- a/ui/pages/repo/empty.go +++ b/ui/pages/repo/empty.go @@ -36,5 +36,5 @@ git push -u origin main git remote add origin %[1]s git push -u origin main `+"```"+` -`, common.CloneCmd(cfg.SSH.PublicURL, repo)) +`, common.RepoURL(cfg.SSH.PublicURL, repo)) }