()
| 4898 | } |
| 4899 | |
| 4900 | func listRemoteBranches() ([]remoteBranch, error) { |
| 4901 | cmd := exec.Command("git", "for-each-ref", "--format=%(refname:short)", "refs/remotes") |
| 4902 | out, err := cmd.Output() |
| 4903 | if err != nil { |
| 4904 | return nil, fmt.Errorf("git for-each-ref refs/remotes: %w", err) |
| 4905 | } |
| 4906 | |
| 4907 | trimmed := strings.TrimSpace(string(out)) |
| 4908 | if trimmed == "" { |
| 4909 | return nil, fmt.Errorf("no remote branches found") |
| 4910 | } |
| 4911 | |
| 4912 | lines := strings.Split(trimmed, "\n") |
| 4913 | branches := make([]remoteBranch, 0, len(lines)) |
| 4914 | |
| 4915 | for _, line := range lines { |
| 4916 | ref := strings.TrimSpace(line) |
| 4917 | if ref == "" { |
| 4918 | continue |
| 4919 | } |
| 4920 | parts := strings.SplitN(ref, "/", 2) |
| 4921 | if len(parts) < 2 { |
| 4922 | continue |
| 4923 | } |
| 4924 | remote := strings.TrimSpace(parts[0]) |
| 4925 | branch := strings.TrimSpace(parts[1]) |
| 4926 | if branch == "" || branch == "HEAD" { |
| 4927 | continue |
| 4928 | } |
| 4929 | branches = append(branches, remoteBranch{ |
| 4930 | Remote: remote, |
| 4931 | Name: branch, |
| 4932 | }) |
| 4933 | } |
| 4934 | |
| 4935 | if len(branches) == 0 { |
| 4936 | return nil, fmt.Errorf("no remote branches found") |
| 4937 | } |
| 4938 | |
| 4939 | sort.Slice(branches, func(i, j int) bool { |
| 4940 | if branches[i].Remote == branches[j].Remote { |
| 4941 | return branches[i].Name < branches[j].Name |
| 4942 | } |
| 4943 | return branches[i].Remote < branches[j].Remote |
| 4944 | }) |
| 4945 | |
| 4946 | return branches, nil |
| 4947 | } |
| 4948 | |
| 4949 | func gitRemoteState(name string) (bool, string, error) { |
| 4950 | cmd := exec.Command("git", "remote", "get-url", name) |
no outgoing calls
no test coverage detected