package git

import "context"

// Fetch 执行 git fetch --all --prune。dir 是 main_path 或 worktree path。
func (r *DefaultRunner) Fetch(ctx context.Context, dir string, cred *Credential) error {
	ctx, cancel := withCtx(ctx, r.cfg.FetchTimeout)
	defer cancel()
	env, cleanup, err := credentialEnv(r.cfg.TmpDir, cred)
	if err != nil {
		return err
	}
	defer cleanup()
	_, _, err = r.exec(ctx, dir, env, "fetch", "--all", "--prune")
	return err
}
