MCPcopy Create free account
hub / github.com/dagger/dagger / fetch

Method fetch

core/git_remote.go:348–481  ·  view source on GitHub ↗
(ctx context.Context, git *gitutil.GitCLI, depth int, includeTags bool, refs []*RemoteGitRef)

Source from the content-addressed store, hash-verified

346}
347
348func (repo *RemoteGitRepository) fetch(ctx context.Context, git *gitutil.GitCLI, depth int, includeTags bool, refs []*RemoteGitRef) error {
349 query, err := CurrentQuery(ctx)
350 if err != nil {
351 return err
352 }
353
354 if len(refs) == 0 && !includeTags {
355 // Nothing requested: avoid an implicit broad fetch from origin.
356 return nil
357 }
358
359 // Fetch by object SHA in the hot path (`--no-tags`), and only retry by named refs for SHA-incompatible remotes.
360 logger := slog.SpanLogger(ctx, InstrumentationLibrary)
361
362 gitDir, err := git.GitDir(ctx)
363 if err != nil {
364 return err
365 }
366
367 shaRefSpecs := make([]string, len(refs))
368 for i, ref := range refs {
369 // Default hot path: fetch exact objects by SHA; ref names are already resolved via ls-remote.
370 shaRefSpecs[i] = ref.SHA
371 }
372
373 runFetch := func(refSpecs []string) error {
374 args := []string{
375 "fetch",
376 "--no-tags",
377 "--update-head-ok",
378 "--force",
379 }
380 if depth <= 0 {
381 if _, err := os.Lstat(filepath.Join(gitDir, "shallow")); err == nil {
382 args = append(args, "--unshallow")
383 }
384 } else {
385 args = append(args, "--depth="+fmt.Sprint(depth))
386 }
387 args = append(args, "origin")
388 args = append(args, refSpecs...)
389
390 if _, err := git.Run(ctx, args...); err != nil {
391 if errors.Is(err, gitutil.ErrShallowNotSupported) {
392 // fallback to full fetch
393 args = slices.DeleteFunc(args, func(s string) bool {
394 return strings.HasPrefix(s, "--depth")
395 })
396 _, err = git.Run(ctx, args...)
397 }
398 if err != nil {
399 return err
400 }
401 }
402 return nil
403 }
404
405 runFetchTags := func() error {

Callers 1

mountMethod · 0.95

Calls 14

SpanLoggerFunction · 0.92
WithIgnoreErrorFunction · 0.92
WithGitDirFunction · 0.92
CurrentQueryFunction · 0.85
namedFetchRefSpecsFunction · 0.85
LstatMethod · 0.80
IsMethod · 0.80
StartBindingsMethod · 0.80
RunMethod · 0.65
NewMethod · 0.65
ServicesMethod · 0.65
RemoteMethod · 0.65

Tested by

no test coverage detected