ParseRemoteTrackingRef parses a string of the form "refs/remotes/ / " into a RemoteTrackingBranch struct. If the string does not match this format, an error is returned. For now, we assume that refnames are of the format " / ", where the remote is a single path component
(s string)
| 554 | // |
| 555 | // When using this ref, git assumes it means `remote: foo` `branch: bar/baz`. |
| 556 | func ParseRemoteTrackingRef(s string) (RemoteTrackingRef, error) { |
| 557 | prefix := "refs/remotes/" |
| 558 | if !strings.HasPrefix(s, prefix) { |
| 559 | return RemoteTrackingRef{}, fmt.Errorf("remote tracking branch must have format refs/remotes/<remote>/<branch> but was: %s", s) |
| 560 | } |
| 561 | |
| 562 | refName := strings.TrimPrefix(s, prefix) |
| 563 | refNameParts := strings.SplitN(refName, "/", 2) |
| 564 | if len(refNameParts) != 2 { |
| 565 | return RemoteTrackingRef{}, fmt.Errorf("remote tracking branch must have format refs/remotes/<remote>/<branch> but was: %s", s) |
| 566 | } |
| 567 | |
| 568 | return RemoteTrackingRef{ |
| 569 | Remote: refNameParts[0], |
| 570 | Branch: refNameParts[1], |
| 571 | }, nil |
| 572 | } |
| 573 | |
| 574 | // PushRevision gets the value of the @{push} revision syntax |
| 575 | // An error here doesn't necessarily mean something is broken, but may mean that the @{push} |