Skip to content

Commit 816761b

Browse files
Chi-IrohThomas Sayen
authored andcommitted
Fixed commit count
1 parent c8c1b33 commit 816761b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

modules/git/commit.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ type CommitsCountOptions struct {
172172

173173
// CommitsCount returns number of total commits of until given revision.
174174
func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error) {
175-
cmd := NewCommand("rev-list", "--count")
175+
cmd := NewCommand(ctx, "--no-pager", "log", "--pretty=format:%H")
176176

177177
cmd.AddDynamicArguments(opts.Revision...)
178178

@@ -181,15 +181,15 @@ func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error)
181181
}
182182

183183
if len(opts.RelPath) > 0 {
184+
cmd.AddOptionValues("--follow")
184185
cmd.AddDashesAndList(opts.RelPath...)
185186
}
186187

187188
stdout, _, err := cmd.RunStdString(ctx, &RunOpts{Dir: opts.RepoPath})
188189
if err != nil {
189190
return 0, err
190191
}
191-
192-
return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
192+
return int64(len(strings.Split(stdout, "\n"))), nil
193193
}
194194

195195
// CommitsCount returns number of total commits of until current revision.

0 commit comments

Comments
 (0)