GetCommitHistory returns commits in chronological order for a HEAD transition.
(repoPath, fromCommit, toCommit string)
| 9 | |
| 10 | // GetCommitHistory returns commits in chronological order for a HEAD transition. |
| 11 | func GetCommitHistory(repoPath, fromCommit, toCommit string) ([]vcs.CommitSummary, error) { |
| 12 | if err := validateGitRef(toCommit); err != nil { |
| 13 | return nil, err |
| 14 | } |
| 15 | args := []string{"log", "--reverse", "--format=%H%x00%h%x00%an%x00%ae%x00%aI%x00%s%x1e"} |
| 16 | if fromCommit == "" || fromCommit == unbornHeadSignature { |
| 17 | args = append(args, toCommit) |
| 18 | } else { |
| 19 | if err := validateGitRef(fromCommit); err != nil { |
| 20 | return nil, err |
| 21 | } |
| 22 | args = append(args, fromCommit+".."+toCommit) |
| 23 | } |
| 24 | |
| 25 | stdout, stderr, err := runGitCommand(repoPath, args...) |
| 26 | if err != nil { |
| 27 | return nil, gitCommandError(err, stderr) |
| 28 | } |
| 29 | |
| 30 | return parseCommitHistory(stdout), nil |
| 31 | } |
| 32 | |
| 33 | func parseCommitHistory(output []byte) []vcs.CommitSummary { |
| 34 | raw := strings.TrimSuffix(string(output), "\x1e\n") |