MCPcopy Index your code
hub / github.com/docker/docker-agent / fetchBase

Function fetchBase

pkg/worktree/worktree.go:361–374  ·  view source on GitHub ↗

fetchBase updates the local copy of a remote-tracking base ref (e.g. "origin/main") so the worktree branches from the latest remote state. Refs that don't name a remote (a local branch, tag, or commit) are left alone. A fetch failure is reported as [ErrInvalidBase]. A fully-qualified refspec (refs/

(ctx context.Context, root, base string)

Source from the content-addressed store, hash-verified

359// would leave the subsequent "git worktree add ... <remote>/<branch>"
360// resolving a stale remote-tracking ref.
361func fetchBase(ctx context.Context, root, base string) error {
362 remote, branch, ok := strings.Cut(base, "/")
363 if !ok {
364 return nil
365 }
366 if !isRemote(ctx, root, remote) {
367 return nil
368 }
369 refspec := "refs/heads/" + branch + ":refs/remotes/" + remote + "/" + branch
370 if err := git(ctx, root, "fetch", remote, refspec); err != nil {
371 return fmt.Errorf("%w: fetching %s: %w", ErrInvalidBase, base, err)
372 }
373 return nil
374}
375
376// isRemote reports whether name is a configured git remote.
377func isRemote(ctx context.Context, root, name string) bool {

Callers 1

CreateFunction · 0.85

Calls 2

isRemoteFunction · 0.85
gitFunction · 0.85

Tested by

no test coverage detected