main
Ariadne Conill 2022-06-28 02:13:05 +00:00
commit 13d7d9c9d1
1 changed files with 40 additions and 0 deletions

40
main.go Normal file
View File

@ -0,0 +1,40 @@
package main
import (
"fmt"
"log"
"net/url"
"strings"
"github.com/go-git/go-git/v5"
)
func main() {
repo, err := git.PlainOpen(".")
if err != nil {
log.Fatal(err)
}
remote, err := repo.Remote("origin")
if err != nil {
log.Fatal(err)
}
remoteConfig := remote.Config()
remoteURL := remoteConfig.URLs[0]
log.Printf("remote = %s", remoteURL)
normalizedURL, err := url.Parse(remoteURL)
if err != nil {
log.Printf("URL is a git+ssh:// type URL")
remoteURL = strings.Replace(remoteURL, ":", "/", 1)
normalizedURL, err = url.Parse(fmt.Sprintf("git+ssh://%s", remoteURL))
if err != nil {
log.Fatal(err)
}
}
log.Printf("normalized url = %s", normalizedURL)
}