aboutsummaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authoryp05327 <576951401@qq.com>2024-04-14 21:18:06 +0900
committerGitHub <noreply@github.com>2024-04-14 14:18:06 +0200
commit928c0d4f460ef2a53766354f2ffc97a7845ac78c (patch)
tree910d1479a637c23f242778ce633ae8b978f92b4f /services
parent222d16e6ea245fe28ada9ad9ad60eab7e886902e (diff)
downloadgitea-928c0d4f460ef2a53766354f2ffc97a7845ac78c.tar.gz
gitea-928c0d4f460ef2a53766354f2ffc97a7845ac78c.zip
Fix mirror error when mirror repo is empty (#30432) (#30467)
Backport #30432 Fix https://github.com/go-gitea/gitea/issues/30424 ps: convert `gitrepo.OpenRepository` to `git.OpenRepository` remove `ctx` from `checkAndUpdateEmptyRepository` Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'services')
-rw-r--r--services/mirror/mirror_pull.go40
1 files changed, 23 insertions, 17 deletions
diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go
index 38b6986c4a..62d2bafaf5 100644
--- a/services/mirror/mirror_pull.go
+++ b/services/mirror/mirror_pull.go
@@ -449,19 +449,17 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
return false
}
- var gitRepo *git.Repository
- if len(results) == 0 {
- log.Trace("SyncMirrors [repo: %-v]: no branches updated", m.Repo)
- } else {
- log.Trace("SyncMirrors [repo: %-v]: %d branches updated", m.Repo, len(results))
- gitRepo, err = git.OpenRepository(ctx, m.Repo.RepoPath())
- if err != nil {
- log.Error("SyncMirrors [repo: %-v]: unable to OpenRepository: %v", m.Repo, err)
- return false
- }
- defer gitRepo.Close()
+ gitRepo, err := git.OpenRepository(ctx, m.Repo.RepoPath())
+ 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(m, gitRepo, results); !ok {
+ log.Error("SyncMirrors [repo: %-v]: checkAndUpdateEmptyRepository: %v", m.Repo, err)
return false
}
}
@@ -533,16 +531,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)
- // Get latest commit date and update to current repository updated time
- commitDate, err := git.GetLatestCommitTime(ctx, m.Repo.RepoPath())
+ isEmpty, err := gitRepo.IsEmpty()
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
}
+ 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)