|
29 | 29 | NoErrAlreadyUpToDate = errors.New("already up-to-date")
|
30 | 30 | ErrDeleteRefNotSupported = errors.New("server does not support delete-refs")
|
31 | 31 | ErrForceNeeded = errors.New("some refs were not updated")
|
| 32 | + ErrExactSHA1NotSupported = errors.New("server does not support exact SHA1 refspec") |
32 | 33 | )
|
33 | 34 |
|
34 | 35 | const (
|
@@ -303,6 +304,10 @@ func (r *Remote) fetch(ctx context.Context, o *FetchOptions) (sto storer.Referen
|
303 | 304 | return nil, err
|
304 | 305 | }
|
305 | 306 |
|
| 307 | + if err := r.isSupportedRefSpec(o.RefSpecs, ar); err != nil { |
| 308 | + return nil, err |
| 309 | + } |
| 310 | + |
306 | 311 | remoteRefs, err := ar.AllReferences()
|
307 | 312 | if err != nil {
|
308 | 313 | return nil, err
|
@@ -546,6 +551,7 @@ func (r *Remote) addReferenceIfRefSpecMatches(rs config.RefSpec,
|
546 | 551 |
|
547 | 552 | func (r *Remote) references() ([]*plumbing.Reference, error) {
|
548 | 553 | var localRefs []*plumbing.Reference
|
| 554 | + |
549 | 555 | iter, err := r.s.IterReferences()
|
550 | 556 | if err != nil {
|
551 | 557 | return nil, err
|
@@ -701,6 +707,11 @@ func doCalculateRefs(
|
701 | 707 | return err
|
702 | 708 | }
|
703 | 709 |
|
| 710 | + if s.IsExactSHA1() { |
| 711 | + ref := plumbing.NewHashReference(s.Dst(""), plumbing.NewHash(s.Src())) |
| 712 | + return refs.SetReference(ref) |
| 713 | + } |
| 714 | + |
704 | 715 | var matched bool
|
705 | 716 | err = iter.ForEach(func(ref *plumbing.Reference) error {
|
706 | 717 | if !s.Match(ref.Name()) {
|
@@ -850,6 +861,26 @@ func (r *Remote) newUploadPackRequest(o *FetchOptions,
|
850 | 861 | return req, nil
|
851 | 862 | }
|
852 | 863 |
|
| 864 | +func (r *Remote) isSupportedRefSpec(refs []config.RefSpec, ar *packp.AdvRefs) error { |
| 865 | + var containsIsExact bool |
| 866 | + for _, ref := range refs { |
| 867 | + if ref.IsExactSHA1() { |
| 868 | + containsIsExact = true |
| 869 | + } |
| 870 | + } |
| 871 | + |
| 872 | + if !containsIsExact { |
| 873 | + return nil |
| 874 | + } |
| 875 | + |
| 876 | + if ar.Capabilities.Supports(capability.AllowReachableSHA1InWant) || |
| 877 | + ar.Capabilities.Supports(capability.AllowTipSHA1InWant) { |
| 878 | + return nil |
| 879 | + } |
| 880 | + |
| 881 | + return ErrExactSHA1NotSupported |
| 882 | +} |
| 883 | + |
853 | 884 | func buildSidebandIfSupported(l *capability.List, reader io.Reader, p sideband.Progress) io.Reader {
|
854 | 885 | var t sideband.Type
|
855 | 886 |
|
@@ -883,7 +914,7 @@ func (r *Remote) updateLocalReferenceStorage(
|
883 | 914 | }
|
884 | 915 |
|
885 | 916 | for _, ref := range fetchedRefs {
|
886 |
| - if !spec.Match(ref.Name()) { |
| 917 | + if !spec.Match(ref.Name()) && !spec.IsExactSHA1() { |
887 | 918 | continue
|
888 | 919 | }
|
889 | 920 |
|
|
0 commit comments