| 202 | } |
| 203 | |
| 204 | func (s *state) gitWorld(opts gitOptions) (string, error) { |
| 205 | if opts.run == "" { |
| 206 | return s.ensureGitFixture() |
| 207 | } |
| 208 | runs, err := s.readRuns() |
| 209 | if err != nil { |
| 210 | return "", err |
| 211 | } |
| 212 | for _, rec := range slices.Backward(runs) { |
| 213 | |
| 214 | if opts.run != "latest" && rec.ID != opts.run { |
| 215 | continue |
| 216 | } |
| 217 | if opts.before { |
| 218 | if rec.GitBaseline == "" || !filepath.IsLocal(rec.GitBaseline) { |
| 219 | return "", fmt.Errorf("run %s has no Git baseline", rec.ID) |
| 220 | } |
| 221 | return filepath.Join(s.dir, filepath.FromSlash(rec.GitBaseline)), nil |
| 222 | } |
| 223 | if opts.build > len(rec.Results) { |
| 224 | return "", fmt.Errorf("run %s has only %d builds", rec.ID, len(rec.Results)) |
| 225 | } |
| 226 | outcome := rec.Results[opts.build-1].Git |
| 227 | if outcome == nil { |
| 228 | return "", fmt.Errorf("run %s build %d has no retained Git workspace", rec.ID, opts.build) |
| 229 | } |
| 230 | if !filepath.IsLocal(outcome.Directory) { |
| 231 | return "", fmt.Errorf("invalid Git workspace in run %s", rec.ID) |
| 232 | } |
| 233 | return filepath.Join(s.dir, filepath.FromSlash(outcome.Directory)), nil |
| 234 | } |
| 235 | return "", fmt.Errorf("no saved run %q", opts.run) |
| 236 | } |
| 237 | |
| 238 | func cmdGit(args []string, stdout, stderr io.Writer) error { |
| 239 | opts, err := parseGitArgs(args) |