Fixed commit count

This commit is contained in:
Thomas Sayen 2025-06-10 10:04:44 +00:00 committed by Thomas Sayen
parent 22f63d918f
commit 88d70d305b
1 changed files with 3 additions and 3 deletions

View File

@ -172,7 +172,7 @@ type CommitsCountOptions struct {
// CommitsCount returns number of total commits of until given revision.
func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error) {
cmd := NewCommand("rev-list", "--count")
cmd := NewCommand(ctx, "--no-pager", "log", "--pretty=format:%H")
cmd.AddDynamicArguments(opts.Revision...)
@ -181,6 +181,7 @@ func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error)
}
if len(opts.RelPath) > 0 {
cmd.AddOptionValues("--follow")
cmd.AddDashesAndList(opts.RelPath...)
}
@ -188,8 +189,7 @@ func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error)
if err != nil {
return 0, err
}
return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
return int64(len(strings.Split(stdout, "\n"))), nil
}
// CommitsCount returns number of total commits of until current revision.