ValidateMappings normalizes all mappings and rejects duplicate target refs.
(mappings []RefMapping, allowOther bool)
| 161 | |
| 162 | // ValidateMappings normalizes all mappings and rejects duplicate target refs. |
| 163 | func ValidateMappings(mappings []RefMapping, allowOther bool) ([]NormalizedMapping, error) { |
| 164 | if len(mappings) == 0 { |
| 165 | return nil, nil |
| 166 | } |
| 167 | |
| 168 | normalized := make([]NormalizedMapping, 0, len(mappings)) |
| 169 | targetSeen := make(map[plumbing.ReferenceName]string, len(mappings)) |
| 170 | |
| 171 | for _, m := range mappings { |
| 172 | nm, err := NormalizeMapping(m, allowOther) |
| 173 | if err != nil { |
| 174 | return nil, err |
| 175 | } |
| 176 | if prev, exists := targetSeen[nm.TargetRef]; exists { |
| 177 | return nil, fmt.Errorf("duplicate target ref %s: mapped from both %q and %q", nm.TargetRef, prev, m.Source) |
| 178 | } |
| 179 | targetSeen[nm.TargetRef] = m.Source |
| 180 | normalized = append(normalized, nm) |
| 181 | } |
| 182 | return normalized, nil |
| 183 | } |
| 184 | |
| 185 | const ( |
| 186 | kindBranch = "branch" |