func Remotes() (remotes []Remote, err error) { re := regexp.MustCompile(`(.+)\s+(.+)\s+\((push|fetch)\)`) rs, err := git.Remotes() if err != nil { err = fmt.Errorf("Can't load git remote") return } remotesMap := make(map[string]string) for _, r := range rs { if re.MatchString(r) { match := re.FindStringSubmatch(r) name := strings.TrimSpace(match[1]) url := strings.TrimSpace(match[2]) remotesMap[name] = url } } for n, u := range remotesMap { url, e := git.ParseURL(u) if e != nil { err = e return } remotes = append(remotes, Remote{Name: n, URL: url}) } return }
func tranformFetchArgs(args *Args) { remotes, err := git.Remotes() utils.Check(err) names := parseRemoteNames(args) gh := github.New() projects := []github.Project{} ownerRegexp := regexp.MustCompile(OwnerRe) for _, name := range names { if ownerRegexp.MatchString(name) && !isRemoteExist(remotes, name) { project := github.NewProjectFromNameAndOwner("", name) repo, err := gh.Repository(project) if err != nil { continue } project = github.NewProjectFromNameAndOwner("", repo.FullName) projects = append(projects, project) } } for _, project := range projects { var isSSH bool if project.Owner == gh.Config.FetchUser() { isSSH = true } args.Before("git", "remote", "add", project.Owner, project.GitURL("", "", isSSH)) } }
func hasGitRemote(name string) bool { remotes, err := git.Remotes() utils.Check(err) for _, remote := range remotes { if remote.Name == name { return true } } return false }
func checkIfRemoteExists(remote string) (bool, error) { remotes, err := git.Remotes() if err != nil { return false, err } for _, r := range remotes { if r.Name == remote { return true, nil } } return false, nil }