| 10 | ) |
| 11 | |
| 12 | func (provider *Provider) ResolveCommitComparison(ctx context.Context) (InputResolution, error) { |
| 13 | head := provider.resolveCommit(ctx, provider.commit) |
| 14 | if head == "" { |
| 15 | return InputResolution{}, fmt.Errorf("cannot resolve commit %q", provider.commit) |
| 16 | } |
| 17 | content, err := provider.runGit(ctx, "cat-file", "commit", head) |
| 18 | if err != nil { |
| 19 | return InputResolution{}, fmt.Errorf("read commit %s: %w", head, err) |
| 20 | } |
| 21 | resolution := InputResolution{ResolvedHead: head, BaseIsEmpty: true} |
| 22 | for line := range strings.SplitSeq(content, "\n") { |
| 23 | if line == "" { |
| 24 | break |
| 25 | } |
| 26 | if parent, ok := strings.CutPrefix(line, "parent "); ok { |
| 27 | if provider.resolveCommit(ctx, parent) != parent { |
| 28 | return InputResolution{}, fmt.Errorf("comparison parent %s is unavailable", parent) |
| 29 | } |
| 30 | parents := provider.commitParents(ctx, head) |
| 31 | if len(parents) == 0 || parents[0] != parent { |
| 32 | return InputResolution{}, fmt.Errorf("comparison parent %s is not visible in Git history; deepen the clone before reviewing this commit", parent) |
| 33 | } |
| 34 | resolution.ResolvedBase = parent |
| 35 | resolution.ExactRange = parent + ".." + head |
| 36 | resolution.BaseIsEmpty = false |
| 37 | break |
| 38 | } |
| 39 | } |
| 40 | return resolution, nil |
| 41 | } |