| 175 | } |
| 176 | |
| 177 | func (t *Tracker) trackGitReferences(ctx context.Context, urls []string, freshen bool) error { |
| 178 | if freshen { |
| 179 | log.Debug("Freshen is enabled") |
| 180 | |
| 181 | tmp := make([]string, len(urls), len(urls)+len(t.TrustedTasks)) |
| 182 | copy(tmp, urls) |
| 183 | urls = tmp |
| 184 | for u := range t.TrustedTasks { |
| 185 | if strings.HasPrefix(u, "git+") { |
| 186 | urls = append(urls, u) |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | g := NewGitTracker() |
| 192 | defer g.Close(ctx) |
| 193 | |
| 194 | for _, u := range urls { |
| 195 | schemeSepIdx := strings.Index(u, "//") |
| 196 | pathSepIdx := strings.LastIndex(u, "//") |
| 197 | |
| 198 | if pathSepIdx <= schemeSepIdx { |
| 199 | return fmt.Errorf("expected %q to contain the `//` to separate the repository from the path, e.g. git+https://github.com/org/repository//task/0.1/task.yaml@f0cacc1a", u) |
| 200 | } |
| 201 | |
| 202 | repository := u[0:pathSepIdx] |
| 203 | rest := u[pathSepIdx+2:] |
| 204 | |
| 205 | path, rev, found := strings.Cut(rest, "@") |
| 206 | if !found { |
| 207 | if !freshen { |
| 208 | return fmt.Errorf("expected %q to contain the revision information following the `@`, e.g. git+https://github.com/org/repository//task/0.1/task.yaml@f0cacc1a, to fetch the latest revision from a remote URL provide the --freshen parameter", u) |
| 209 | } |
| 210 | var err error |
| 211 | rev, err = g.GitResolve(ctx, repository, rest) |
| 212 | if err != nil { |
| 213 | return err |
| 214 | } |
| 215 | path = rest |
| 216 | } else if freshen { |
| 217 | // nothing prevents the user using --freshen and revision, so log what revision is being used. |
| 218 | log.Debugf("--freshen used, but a revision is also provided. Using provided revision: %q", rev) |
| 219 | } |
| 220 | |
| 221 | t.addTrustedTaskRecord("", taskRecord{ |
| 222 | Repository: fmt.Sprintf("%s//%s", repository, path), |
| 223 | Ref: rev, |
| 224 | }) |
| 225 | } |
| 226 | |
| 227 | return nil |
| 228 | } |
| 229 | |
| 230 | func inputBundleTags(ctx context.Context, t Tracker) ([]image.ImageReference, error) { |
| 231 | uniqueTagRefs := map[string]bool{} |