MCPcopy
hub / github.com/harness/harness / ListCommits

Method ListCommits

git/api/commit.go:193–236  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

191// Note: ref & afterRef can be Branch / Tag / CommitSHA.
192// Note: commits returned are [ref->...->afterRef).
193func (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
238func getCommitFileStats(
239 ctx context.Context,

Callers

nothing calls this directly

Calls 6

listCommitSHAsMethod · 0.95
CatFileCommitsFunction · 0.85
getCommitFileStatsFunction · 0.85
getRenameDetailsFunction · 0.85
cleanupCommitsForRenameFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected