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

Method resolveGitRef

pkg/remote/git.go:172–193  ·  view source on GitHub ↗
(ctx context.Context, path string, ref *gitutil.GitRef)

Source from the content-addressed store, hash-verified

170}
171
172func (g gitRemoteLoader) resolveGitRef(ctx context.Context, path string, ref *gitutil.GitRef) error {
173 if !commitSHA.MatchString(ref.Ref) {
174 cmd := exec.CommandContext(ctx, "git", "ls-remote", "--exit-code", ref.Remote, ref.Ref)
175 cmd.Env = g.gitCommandEnv()
176 out, err := cmd.CombinedOutput()
177 if err != nil {
178 if cmd.ProcessState.ExitCode() == 2 {
179 return fmt.Errorf("repository does not contain ref %s, output: %q: %w", path, string(out), err)
180 }
181 return fmt.Errorf("failed to access repository at %s:\n %s", ref.Remote, out)
182 }
183 if len(out) < 40 {
184 return fmt.Errorf("unexpected git command output: %q", string(out))
185 }
186 sha := string(out[:40])
187 if !commitSHA.MatchString(sha) {
188 return fmt.Errorf("invalid commit sha %q", sha)
189 }
190 ref.Ref = sha
191 }
192 return nil
193}
194
195func (g gitRemoteLoader) checkout(ctx context.Context, path string, ref *gitutil.GitRef) error {
196 err := os.MkdirAll(path, 0o700)

Callers 1

LoadMethod · 0.95

Calls 2

gitCommandEnvMethod · 0.95
ExitCodeMethod · 0.80

Tested by

no test coverage detected