mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 14:53:34 +01:00
Fix mirror error when mirror repo is empty (#30432)
Fix #30424 Co-authored-by: Giteabot <teabot@gitea.io> (cherry picked from commit b4d86912ef18c58e973ee10c4a3bc621e9bd6c52)
This commit is contained in:
parent
c08b3a8ebd
commit
6cc141516b
1 changed files with 23 additions and 17 deletions
|
@ -449,19 +449,17 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
var gitRepo *git.Repository
|
gitRepo, err := gitrepo.OpenRepository(ctx, m.Repo)
|
||||||
if len(results) == 0 {
|
if err != nil {
|
||||||
log.Trace("SyncMirrors [repo: %-v]: no branches updated", m.Repo)
|
log.Error("SyncMirrors [repo: %-v]: unable to OpenRepository: %v", m.Repo, err)
|
||||||
} else {
|
return false
|
||||||
log.Trace("SyncMirrors [repo: %-v]: %d branches updated", m.Repo, len(results))
|
}
|
||||||
gitRepo, err = gitrepo.OpenRepository(ctx, m.Repo)
|
defer gitRepo.Close()
|
||||||
if err != nil {
|
|
||||||
log.Error("SyncMirrors [repo: %-v]: unable to OpenRepository: %v", m.Repo, err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
defer gitRepo.Close()
|
|
||||||
|
|
||||||
|
log.Trace("SyncMirrors [repo: %-v]: %d branches updated", m.Repo, len(results))
|
||||||
|
if len(results) > 0 {
|
||||||
if ok := checkAndUpdateEmptyRepository(ctx, m, gitRepo, results); !ok {
|
if ok := checkAndUpdateEmptyRepository(ctx, m, gitRepo, results); !ok {
|
||||||
|
log.Error("SyncMirrors [repo: %-v]: checkAndUpdateEmptyRepository: %v", m.Repo, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -534,16 +532,24 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
||||||
}
|
}
|
||||||
log.Trace("SyncMirrors [repo: %-v]: done notifying updated branches/tags - now updating last commit time", m.Repo)
|
log.Trace("SyncMirrors [repo: %-v]: done notifying updated branches/tags - now updating last commit time", m.Repo)
|
||||||
|
|
||||||
// Get latest commit date and update to current repository updated time
|
isEmpty, err := gitRepo.IsEmpty()
|
||||||
commitDate, err := git.GetLatestCommitTime(ctx, m.Repo.RepoPath())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("SyncMirrors [repo: %-v]: unable to GetLatestCommitDate: %v", m.Repo, err)
|
log.Error("SyncMirrors [repo: %-v]: unable to check empty git repo: %v", m.Repo, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if !isEmpty {
|
||||||
|
// Get latest commit date and update to current repository updated time
|
||||||
|
commitDate, err := git.GetLatestCommitTime(ctx, m.Repo.RepoPath())
|
||||||
|
if err != nil {
|
||||||
|
log.Error("SyncMirrors [repo: %-v]: unable to GetLatestCommitDate: %v", m.Repo, err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = repo_model.UpdateRepositoryUpdatedTime(ctx, m.RepoID, commitDate); err != nil {
|
||||||
|
log.Error("SyncMirrors [repo: %-v]: unable to update repository 'updated_unix': %v", m.Repo, err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if err = repo_model.UpdateRepositoryUpdatedTime(ctx, m.RepoID, commitDate); err != nil {
|
|
||||||
log.Error("SyncMirrors [repo: %-v]: unable to update repository 'updated_unix': %v", m.Repo, err)
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Trace("SyncMirrors [repo: %-v]: Successfully updated", m.Repo)
|
log.Trace("SyncMirrors [repo: %-v]: Successfully updated", m.Repo)
|
||||||
|
|
Loading…
Reference in a new issue