commitParents returns the parent commit SHAs of ref: zero for a root commit, one for an ordinary commit, and 2+ for a merge. It uses `rev-list --parents -n 1`, whose single line is " …" — the leading commit token is dropped, the rest are the parents. `rev-list` (unlike `re
(ctx context.Context, ref string)
| 594 | // looks like an option. An error yields nil so the caller treats it as "no |
| 595 | // unique base". |
| 596 | func (p *Provider) commitParents(ctx context.Context, ref string) []string { |
| 597 | out, err := p.runGit(ctx, "rev-list", "--parents", "-n", "1", "--end-of-options", ref) |
| 598 | if err != nil { |
| 599 | return nil |
| 600 | } |
| 601 | fields := strings.Fields(firstLine(out)) |
| 602 | if len(fields) <= 1 { |
| 603 | return nil // root commit (only the commit itself, no parents) or empty |
| 604 | } |
| 605 | return fields[1:] |
| 606 | } |
| 607 | |
| 608 | // firstLine returns the first non-empty trimmed line of git output, so a stray |
| 609 | // trailing newline or an unexpected second line never pollutes a resolved SHA. |
no test coverage detected