@@ -293,7 +293,7 @@ func (repo *Repository) FileChangedBetweenCommits(filename, id1, id2 string) (bo
293
293
294
294
// FileCommitsCount return the number of files at a revison
295
295
func (repo * Repository ) FileCommitsCount (revision , file string ) (int64 , error ) {
296
- return commitsCount (repo .Path , revision , file )
296
+ return commitsCount (repo .Path , [] string { revision }, [] string { file } )
297
297
}
298
298
299
299
// CommitsByFileAndRange return the commits according revison file and the page
@@ -319,6 +319,11 @@ func (repo *Repository) CommitsByFileAndRangeNoFollow(revision, file string, pag
319
319
// FilesCountBetween return the number of files changed between two commits
320
320
func (repo * Repository ) FilesCountBetween (startCommitID , endCommitID string ) (int , error ) {
321
321
stdout , err := NewCommand ("diff" , "--name-only" , startCommitID + "..." + endCommitID ).RunInDir (repo .Path )
322
+ if err != nil && strings .Contains (err .Error (), "no merge base" ) {
323
+ // git >= 2.28 now returns an error if startCommitID and endCommitID have become unrelated.
324
+ // previously it would return the results of git diff --name-only startCommitID endCommitID so let's try that...
325
+ stdout , err = NewCommand ("diff" , "--name-only" , startCommitID , endCommitID ).RunInDir (repo .Path )
326
+ }
322
327
if err != nil {
323
328
return 0 , err
324
329
}
@@ -333,6 +338,11 @@ func (repo *Repository) CommitsBetween(last *Commit, before *Commit) (*list.List
333
338
stdout , err = NewCommand ("rev-list" , last .ID .String ()).RunInDirBytes (repo .Path )
334
339
} else {
335
340
stdout , err = NewCommand ("rev-list" , before .ID .String ()+ "..." + last .ID .String ()).RunInDirBytes (repo .Path )
341
+ if err != nil && strings .Contains (err .Error (), "no merge base" ) {
342
+ // future versions of git >= 2.28 are likely to return an error if before and last have become unrelated.
343
+ // previously it would return the results of git rev-list before last so let's try that...
344
+ stdout , err = NewCommand ("rev-list" , before .ID .String (), last .ID .String ()).RunInDirBytes (repo .Path )
345
+ }
336
346
}
337
347
if err != nil {
338
348
return nil , err
@@ -348,6 +358,11 @@ func (repo *Repository) CommitsBetweenLimit(last *Commit, before *Commit, limit,
348
358
stdout , err = NewCommand ("rev-list" , "--max-count" , strconv .Itoa (limit ), "--skip" , strconv .Itoa (skip ), last .ID .String ()).RunInDirBytes (repo .Path )
349
359
} else {
350
360
stdout , err = NewCommand ("rev-list" , "--max-count" , strconv .Itoa (limit ), "--skip" , strconv .Itoa (skip ), before .ID .String ()+ "..." + last .ID .String ()).RunInDirBytes (repo .Path )
361
+ if err != nil && strings .Contains (err .Error (), "no merge base" ) {
362
+ // future versions of git >= 2.28 are likely to return an error if before and last have become unrelated.
363
+ // previously it would return the results of git rev-list --max-count n before last so let's try that...
364
+ stdout , err = NewCommand ("rev-list" , "--max-count" , strconv .Itoa (limit ), "--skip" , strconv .Itoa (skip ), before .ID .String (), last .ID .String ()).RunInDirBytes (repo .Path )
365
+ }
351
366
}
352
367
if err != nil {
353
368
return nil , err
@@ -373,7 +388,14 @@ func (repo *Repository) CommitsBetweenIDs(last, before string) (*list.List, erro
373
388
374
389
// CommitsCountBetween return numbers of commits between two commits
375
390
func (repo * Repository ) CommitsCountBetween (start , end string ) (int64 , error ) {
376
- return commitsCount (repo .Path , start + "..." + end , "" )
391
+ count , err := commitsCount (repo .Path , []string {start + "..." + end }, []string {})
392
+ if err != nil && strings .Contains (err .Error (), "no merge base" ) {
393
+ // future versions of git >= 2.28 are likely to return an error if before and last have become unrelated.
394
+ // previously it would return the results of git rev-list before last so let's try that...
395
+ return commitsCount (repo .Path , []string {start , end }, []string {})
396
+ }
397
+
398
+ return count , err
377
399
}
378
400
379
401
// commitsBefore the limit is depth, not total number of returned commits.
0 commit comments