MCPcopy Index your code
hub / github.com/dagger/dagger / loadContextualGitArg

Method loadContextualGitArg

core/modfunc.go:1091–1180  ·  view source on GitHub ↗

loadContextualGitArg resolves a +defaultPath argument for GitRepository or GitRef types. For local modules with a local git path (. or .git), it uses a cache-keyed selector to prevent errant reloads. Otherwise it loads from the module context or parses a remote git URL.

(
	ctx context.Context,
	dag *dagql.Server,
	arg *FunctionArg,
)

Source from the content-addressed store, hash-verified

1089// a cache-keyed selector to prevent errant reloads. Otherwise it loads from
1090// the module context or parses a remote git URL.
1091func (fn *ModuleFunction) loadContextualGitArg(
1092 ctx context.Context,
1093 dag *dagql.Server,
1094 arg *FunctionArg,
1095) (dagql.IDType, error) {
1096 isLocalMod := fn.mod.Self().ContextSource.Value.Self().Kind == ModuleSourceKindLocal
1097 cleanedPath := filepath.Clean(strings.Trim(arg.DefaultPath, "/"))
1098 isLocalGit := cleanedPath == "." || cleanedPath == ".git"
1099
1100 if isLocalMod && isLocalGit {
1101 switch arg.TypeDef.Self().AsObject.Value.Self().Name {
1102 case "GitRepository":
1103 repo, err := fn.mod.Self().ContextSource.Value.Self().LoadContextGit(ctx, dag)
1104 if err != nil {
1105 return nil, fmt.Errorf("load contextual git repository %q: %w", arg.DefaultPath, err)
1106 }
1107 repoID, err := repo.ID()
1108 if err != nil {
1109 return nil, fmt.Errorf("get contextual git repository ID %q: %w", arg.DefaultPath, err)
1110 }
1111 return dagql.NewID[*GitRepository](repoID), nil
1112
1113 case "GitRef":
1114 repo, err := fn.mod.Self().ContextSource.Value.Self().LoadContextGit(ctx, dag)
1115 if err != nil {
1116 return nil, fmt.Errorf("load contextual git ref %q: %w", arg.DefaultPath, err)
1117 }
1118 var gitRef dagql.ObjectResult[*GitRef]
1119 err = dag.Select(ctx, repo, &gitRef,
1120 dagql.Selector{Field: "head"},
1121 )
1122 if err != nil {
1123 return nil, fmt.Errorf("load contextual git ref %q: %w", arg.DefaultPath, err)
1124 }
1125 gitRefID, err := gitRef.ID()
1126 if err != nil {
1127 return nil, fmt.Errorf("get contextual git ref ID %q: %w", arg.DefaultPath, err)
1128 }
1129 return dagql.NewID[*GitRef](gitRefID), nil
1130 }
1131 }
1132
1133 var git dagql.ObjectResult[*GitRepository]
1134 if isLocalGit {
1135 var err error
1136 git, err = fn.mod.Self().ContextSource.Value.Self().LoadContextGit(ctx, dag)
1137 if err != nil {
1138 return nil, err
1139 }
1140 } else if gitURL, err := gitutil.ParseURL(arg.DefaultPath); err == nil {
1141 args := []dagql.NamedInput{
1142 {Name: "url", Value: dagql.String(gitURL.String())},
1143 }
1144 if gitURL.Fragment != nil {
1145 args = append(args, dagql.NamedInput{Name: "ref", Value: dagql.String(gitURL.Fragment.Ref)})
1146 }
1147 err := dag.Select(ctx, dag.Root(), &git,
1148 dagql.Selector{Field: "git", Args: args},

Callers 2

loadContextualArgMethod · 0.95

Calls 8

ParseURLFunction · 0.92
StringTypeAlias · 0.92
SelfMethod · 0.80
LoadContextGitMethod · 0.80
IDMethod · 0.65
SelectMethod · 0.65
StringMethod · 0.65
RootMethod · 0.45

Tested by

no test coverage detected