MCPcopy
hub / github.com/mislav/hub / RemoteBranchAndProject

Method RemoteBranchAndProject

github/localrepo.go:128–192  ·  view source on GitHub ↗
(owner string, preferUpstream bool)

Source from the content-addressed store, hash-verified

126}
127
128func (r *GitHubRepo) RemoteBranchAndProject(owner string, preferUpstream bool) (branch *Branch, project *Project, err error) {
129 if err = r.loadRemotes(); err != nil {
130 return
131 }
132
133 for _, remote := range r.remotes {
134 if p, err := remote.Project(); err == nil {
135 project = p
136 break
137 }
138 }
139
140 branch, err = r.CurrentBranch()
141 if err != nil {
142 return
143 }
144
145 if project == nil {
146 return
147 }
148
149 pushDefault, _ := git.Config("push.default")
150 if pushDefault == "upstream" || pushDefault == "tracking" {
151 upstream, e := branch.Upstream()
152 if e == nil && upstream.IsRemote() {
153 remote, e := r.RemoteByName(upstream.RemoteName())
154 if e == nil {
155 p, e := remote.Project()
156 if e == nil {
157 branch = upstream
158 project = p
159 return
160 }
161 }
162 }
163 }
164
165 shortName := branch.ShortName()
166 remotes := r.remotesForPublish(owner)
167 if preferUpstream {
168 // reverse the remote lookup order; see OriginNamesInLookupOrder
169 remotesInOrder := []Remote{}
170 for i := len(remotes) - 1; i >= 0; i-- {
171 remotesInOrder = append(remotesInOrder, remotes[i])
172 }
173 remotes = remotesInOrder
174 }
175
176 for _, remote := range remotes {
177 p, e := remote.Project()
178 if e != nil {
179 continue
180 }
181 // NOTE: this is similar RemoteForBranch
182 if git.HasFile("refs", "remotes", remote.Name, shortName) {
183 name := fmt.Sprintf("refs/remotes/%s/%s", remote.Name, shortName)
184 branch = &Branch{r, name}
185 project = p

Callers 2

browseFunction · 0.80
pullRequestFunction · 0.80

Calls 11

loadRemotesMethod · 0.95
CurrentBranchMethod · 0.95
RemoteByNameMethod · 0.95
remotesForPublishMethod · 0.95
ConfigFunction · 0.92
HasFileFunction · 0.92
ProjectMethod · 0.80
UpstreamMethod · 0.80
IsRemoteMethod · 0.80
RemoteNameMethod · 0.80
ShortNameMethod · 0.80

Tested by

no test coverage detected