@@ -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 = git .OpenRepository (ctx , m .Repo .RepoPath ())
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 := git .OpenRepository (ctx , m .Repo .RepoPath ())
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 (m , gitRepo , results ); ! ok {
462
+ log .Error ("SyncMirrors [repo: %-v]: checkAndUpdateEmptyRepository: %v" , m .Repo , err )
465
463
return false
466
464
}
467
465
}
@@ -533,16 +531,24 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
533
531
}
534
532
log .Trace ("SyncMirrors [repo: %-v]: done notifying updated branches/tags - now updating last commit time" , m .Repo )
535
533
536
- // Get latest commit date and update to current repository updated time
537
- commitDate , err := git .GetLatestCommitTime (ctx , m .Repo .RepoPath ())
534
+ isEmpty , err := gitRepo .IsEmpty ()
538
535
if err != nil {
539
- log .Error ("SyncMirrors [repo: %-v]: unable to GetLatestCommitDate : %v" , m .Repo , err )
536
+ log .Error ("SyncMirrors [repo: %-v]: unable to check empty git repo : %v" , m .Repo , err )
540
537
return false
541
538
}
539
+ if ! isEmpty {
540
+ // Get latest commit date and update to current repository updated time
541
+ commitDate , err := git .GetLatestCommitTime (ctx , m .Repo .RepoPath ())
542
+ if err != nil {
543
+ log .Error ("SyncMirrors [repo: %-v]: unable to GetLatestCommitDate: %v" , m .Repo , err )
544
+ return false
545
+ }
546
+
547
+ if err = repo_model .UpdateRepositoryUpdatedTime (ctx , m .RepoID , commitDate ); err != nil {
548
+ log .Error ("SyncMirrors [repo: %-v]: unable to update repository 'updated_unix': %v" , m .Repo , err )
549
+ return false
550
+ }
542
551
543
- if err = repo_model .UpdateRepositoryUpdatedTime (ctx , m .RepoID , commitDate ); err != nil {
544
- log .Error ("SyncMirrors [repo: %-v]: unable to update repository 'updated_unix': %v" , m .Repo , err )
545
- return false
546
552
}
547
553
548
554
log .Trace ("SyncMirrors [repo: %-v]: Successfully updated" , m .Repo )
0 commit comments