GetRemote retrieves the remote origin
(localPath string)
| 59 | |
| 60 | // GetRemote retrieves the remote origin |
| 61 | func GetRemote(localPath string) (string, error) { |
| 62 | _, err := os.Stat(localPath + "/.git") |
| 63 | if err != nil { |
| 64 | return "", err |
| 65 | } |
| 66 | |
| 67 | repo, err := git.PlainOpen(localPath) |
| 68 | if err != nil { |
| 69 | return "", errors.Wrap(err, "git open") |
| 70 | } |
| 71 | |
| 72 | remotes, err := repo.Remotes() |
| 73 | if err != nil { |
| 74 | return "", errors.Wrap(err, "get remotes") |
| 75 | } |
| 76 | |
| 77 | if len(remotes) == 0 { |
| 78 | return "", errors.Errorf("Couldn't determine git remote in %s", localPath) |
| 79 | } |
| 80 | |
| 81 | urls := remotes[0].Config().URLs |
| 82 | if len(urls) == 0 { |
| 83 | return "", errors.New("No remotes found") |
| 84 | } |
| 85 | |
| 86 | return urls[0], nil |
| 87 | } |
| 88 | |
| 89 | func GetLatestVersion(repository string) (string, error) { |
| 90 | client := &http.Client{ |