ListCommits lists the commits reachable from ref. Note: ref & afterRef can be Branch / Tag / CommitSHA. Note: commits returned are [ref->...->afterRef).
( ctx context.Context, repoPath string, ref string, page int, limit int, includeStats bool, filter CommitFilter, )
| 191 | // Note: ref & afterRef can be Branch / Tag / CommitSHA. |
| 192 | // Note: commits returned are [ref->...->afterRef). |
| 193 | func (g *Git) ListCommits( |
| 194 | ctx context.Context, |
| 195 | repoPath string, |
| 196 | ref string, |
| 197 | page int, |
| 198 | limit int, |
| 199 | includeStats bool, |
| 200 | filter CommitFilter, |
| 201 | ) ([]Commit, []PathRenameDetails, error) { |
| 202 | if repoPath == "" { |
| 203 | return nil, nil, ErrRepositoryPathEmpty |
| 204 | } |
| 205 | |
| 206 | commitSHAs, err := g.listCommitSHAs(ctx, repoPath, nil, ref, page, limit, filter) |
| 207 | if err != nil { |
| 208 | return nil, nil, fmt.Errorf("failed to list commit SHAs: %w", err) |
| 209 | } |
| 210 | |
| 211 | commits, err := CatFileCommits(ctx, repoPath, nil, commitSHAs) |
| 212 | if err != nil { |
| 213 | return nil, nil, fmt.Errorf("failed to list commits by SHAs: %w", err) |
| 214 | } |
| 215 | |
| 216 | if includeStats { |
| 217 | for i := range commits { |
| 218 | fileStats, err := getCommitFileStats(ctx, repoPath, commits[i].SHA) |
| 219 | if err != nil { |
| 220 | return nil, nil, fmt.Errorf("encountered error getting commit file stats: %w", err) |
| 221 | } |
| 222 | commits[i].FileStats = fileStats |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | if len(filter.Path) != 0 { |
| 227 | renameDetailsList, err := getRenameDetails(ctx, repoPath, commits, filter.Path) |
| 228 | if err != nil { |
| 229 | return nil, nil, err |
| 230 | } |
| 231 | cleanedUpCommits := cleanupCommitsForRename(commits, renameDetailsList, filter.Path) |
| 232 | return cleanedUpCommits, renameDetailsList, nil |
| 233 | } |
| 234 | |
| 235 | return commits, nil, nil |
| 236 | } |
| 237 | |
| 238 | func getCommitFileStats( |
| 239 | ctx context.Context, |
nothing calls this directly
no test coverage detected