(ctx context.Context, path string, ref *gitutil.GitRef)
| 170 | } |
| 171 | |
| 172 | func (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 | |
| 195 | func (g gitRemoteLoader) checkout(ctx context.Context, path string, ref *gitutil.GitRef) error { |
| 196 | err := os.MkdirAll(path, 0o700) |
no test coverage detected