Merge pull request #57 from entireio/nodo/peeled-refs · Entire

Merge pull request #57 from entireio/nodo/peeled-refs

991656a→main·

nodo·2mo ago·2 files·+39 added/-1 removed

gitproto: drop peeled "^{}" refs from AdvRefsToSlice

Changes

2

86 unmodified lines

87
88
89
90
91
92
93
94
95
96
97
98
99
100
95
101
102
103
104
105
106
107
108
109
110
111

86 unmodified lines

}

// AdvRefsToSlice converts an AdvRefs to a slice of references.
//
// Peeled tag entries (names ending in "^{}") are dropped: they are
// wire-protocol metadata exposing the commit a tag points to, not real refs.
// Including them in target ref maps causes the planner to schedule a delete
// for a non-existent ref, which receive-pack rejects with HTTP 400
// "invalid reference name".
func AdvRefsToSlice(ar *packp.AdvRefs) ([]*plumbing.Reference, error) {
    refs, err := ar.ResolvedReferences()
    if err != nil {
        return nil, fmt.Errorf("resolved references: %w", err)
    }
    return refs, nil
    out := refs[:0]
    for _, ref := range refs {
        if ref.Name().IsPeeled() {
            continue
        }
        out = append(out, ref)
        }
    return out, nil
}

// AdvRefsCaps returns the sorted capability list from an AdvRefs.

Minternal/gitproto/refs.go+14/-1

129 unmodified lines

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160

129 unmodified lines

}

// Regression: v1 advertisements include peeled "^{}" entries for annotated tags
// to expose the commit the tag points at. They are wire-protocol metadata, not
// real refs — receive-pack rejects them with "invalid reference name" when the
// planner schedules a delete for one. AdvRefsToSlice must drop them.
func TestAdvRefsToSliceDropsPeeledTagEntries(t *testing.T) {
    adv := &packp.AdvRefs{}
    tagHash := plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    commitHash := plumbing.NewHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
    adv.References = []*plumbing.Reference{
        plumbing.NewHashReference("refs/tags/v1", tagHash),
        plumbing.NewHashReference("refs/tags/v1^{}", commitHash),
    }

refs, err := AdvRefsToSlice(adv)
    if err != nil {
        t.Fatalf("AdvRefsToSlice: %v", err)
    }
    if len(refs) != 1 {
        t.Fatalf("expected 1 ref after peeled drop, got %d: %v", len(refs), refs)
    }
    if refs[0].Name() != "refs/tags/v1" {
        t.Errorf("got %s, want refs/tags/v1", refs[0].Name())
    }
}

func TestDecodeV1AdvRefs(t *testing.T) {
    // Empty data should return ErrEmptyRemoteRepository.
    _, err := decodeV1AdvRefs(nil)