@@ -449,19 +449,17 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
449
449
return false
450
450
}
451
451
452
- var gitRepo * git.Repository
453
- if len (results ) == 0 {
454
- log .Trace ("SyncMirrors [repo: %-v]: no branches updated" , m .Repo )
455
- } else {
456
- log .Trace ("SyncMirrors [repo: %-v]: %d branches updated" , m .Repo , len (results ))
457
- gitRepo , err = gitrepo .OpenRepository (ctx , m .Repo )
458
- if err != nil {
459
- log .Error ("SyncMirrors [repo: %-v]: unable to OpenRepository: %v" , m .Repo , err )
460
- return false
461
- }
462
- defer gitRepo .Close ()
452
+ gitRepo , err := gitrepo .OpenRepository (ctx , m .Repo )
453
+ if err != nil {
454
+ log .Error ("SyncMirrors [repo: %-v]: unable to OpenRepository: %v" , m .Repo , err )
455
+ return false
456
+ }
457
+ defer gitRepo .Close ()
463
458
459
+ log .Trace ("SyncMirrors [repo: %-v]: %d branches updated" , m .Repo , len (results ))
460
+ if len (results ) > 0 {
464
461
if ok := checkAndUpdateEmptyRepository (ctx , m , gitRepo , results ); ! ok {
462
+ log .Error ("SyncMirrors [repo: %-v]: checkAndUpdateEmptyRepository: %v" , m .Repo , err )
465
463
return false
466
464
}
467
465
}
@@ -534,16 +532,24 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
534
532
}
535
533
log .Trace ("SyncMirrors [repo: %-v]: done notifying updated branches/tags - now updating last commit time" , m .Repo )
536
534
537
- // Get latest commit date and update to current repository updated time
538
- commitDate , err := git .GetLatestCommitTime (ctx , m .Repo .RepoPath ())
535
+ isEmpty , err := gitRepo .IsEmpty ()
539
536
if err != nil {
540
- log .Error ("SyncMirrors [repo: %-v]: unable to GetLatestCommitDate : %v" , m .Repo , err )
537
+ log .Error ("SyncMirrors [repo: %-v]: unable to check empty git repo : %v" , m .Repo , err )
541
538
return false
542
539
}
540
+ if ! isEmpty {
541
+ // Get latest commit date and update to current repository updated time
542
+ commitDate , err := git .GetLatestCommitTime (ctx , m .Repo .RepoPath ())
543
+ if err != nil {
544
+ log .Error ("SyncMirrors [repo: %-v]: unable to GetLatestCommitDate: %v" , m .Repo , err )
545
+ return false
546
+ }
547
+
548
+ if err = repo_model .UpdateRepositoryUpdatedTime (ctx , m .RepoID , commitDate ); err != nil {
549
+ log .Error ("SyncMirrors [repo: %-v]: unable to update repository 'updated_unix': %v" , m .Repo , err )
550
+ return false
551
+ }
543
552
544
- if err = repo_model .UpdateRepositoryUpdatedTime (ctx , m .RepoID , commitDate ); err != nil {
545
- log .Error ("SyncMirrors [repo: %-v]: unable to update repository 'updated_unix': %v" , m .Repo , err )
546
- return false
547
553
}
548
554
549
555
log .Trace ("SyncMirrors [repo: %-v]: Successfully updated" , m .Repo )
0 commit comments