MCPcopy
hub / github.com/docker/compose / Load

Method Load

pkg/remote/git.go:75–131  ·  view source on GitHub ↗
(ctx context.Context, path string)

Source from the content-addressed store, hash-verified

73var commitSHA = regexp.MustCompile(`^[a-f0-9]{40}$`)
74
75func (g gitRemoteLoader) Load(ctx context.Context, path string) (string, error) {
76 enabled, err := gitRemoteLoaderEnabled()
77 if err != nil {
78 return "", err
79 }
80 if !enabled {
81 return "", fmt.Errorf("git remote resource is disabled by %q", GIT_REMOTE_ENABLED)
82 }
83
84 ref, _, err := gitutil.ParseGitRef(path)
85 if err != nil {
86 return "", err
87 }
88
89 local, ok := g.known[path]
90 if !ok {
91 if ref.Ref == "" {
92 ref.Ref = "HEAD" // default branch
93 }
94
95 err = g.resolveGitRef(ctx, path, ref)
96 if err != nil {
97 return "", err
98 }
99
100 cache, err := cacheDir()
101 if err != nil {
102 return "", fmt.Errorf("initializing remote resource cache: %w", err)
103 }
104
105 local = filepath.Join(cache, ref.Ref)
106 if _, err := os.Stat(local); os.IsNotExist(err) {
107 if g.offline {
108 return "", nil
109 }
110 err = g.checkout(ctx, local, ref)
111 if err != nil {
112 return "", err
113 }
114 }
115 g.known[path] = local
116 }
117 if ref.SubDir != "" {
118 if err := validateGitSubDir(local, ref.SubDir); err != nil {
119 return "", err
120 }
121 local = filepath.Join(local, ref.SubDir)
122 }
123 stat, err := os.Stat(local)
124 if err != nil {
125 return "", err
126 }
127 if stat.IsDir() {
128 local, err = findFile(cli.DefaultFileNames, local)
129 }
130 return local, err
131}
132

Callers 3

doTestFunction · 0.45
UpMethod · 0.45

Calls 6

resolveGitRefMethod · 0.95
checkoutMethod · 0.95
gitRemoteLoaderEnabledFunction · 0.85
cacheDirFunction · 0.85
validateGitSubDirFunction · 0.85
findFileFunction · 0.85

Tested by 2

doTestFunction · 0.36