s
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package gitcmd
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (r *Repository) ListCommitsByPath(ref, path string, limit int) ([]Commit, error) {
|
||||
if empty, err := r.IsEmpty(); err != nil {
|
||||
return nil, err
|
||||
} else if empty {
|
||||
return []Commit{}, nil
|
||||
}
|
||||
if ref == "" {
|
||||
ref = "HEAD"
|
||||
}
|
||||
|
||||
cmd := NewCommand("log", "--follow").
|
||||
Add("--format=%H%x1f%h%x1f%s%x1f%an%x1f%ae%x1f%aI%x1f%P").
|
||||
WithDir(r.Path)
|
||||
if limit > 0 {
|
||||
cmd.Add("-n", strconv.Itoa(limit))
|
||||
}
|
||||
cmd.AddDynamicArguments(ref)
|
||||
cmd.AddDashesAndList(path)
|
||||
|
||||
out, _, err := cmd.RunStdString(r.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var commits []Commit
|
||||
for _, line := range strings.Split(strings.TrimSpace(out), "\n") {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
commits = append(commits, *parseCommitLine(line))
|
||||
}
|
||||
return commits, nil
|
||||
}
|
||||
Reference in New Issue
Block a user