From cb24cbc1fc316beffe7845d30c5ab0975e32ddb9 Mon Sep 17 00:00:00 2001 From: manuelluis Date: Sun, 6 Dec 2020 05:30:28 +0100 Subject: [PATCH] Fix branch/tag notifications in mirror sync (#13855) (#13862) Co-authored-by: Gitea Co-authored-by: 6543 <6543@obermui.de> --- services/mirror/mirror.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/services/mirror/mirror.go b/services/mirror/mirror.go index 5eafdab38..34d0f0a06 100644 --- a/services/mirror/mirror.go +++ b/services/mirror/mirror.go @@ -149,6 +149,11 @@ func parseRemoteUpdateOutput(output string) []*mirrorSyncResult { switch { case strings.HasPrefix(lines[i], " * "): // New reference + if strings.HasPrefix(lines[i], " * [new tag]") { + refName = git.TagPrefix + refName + } else if strings.HasPrefix(lines[i], " * [new branch]") { + refName = git.BranchPrefix + refName + } results = append(results, &mirrorSyncResult{ refName: refName, oldCommitID: gitShortEmptySha, @@ -434,6 +439,17 @@ func syncMirror(repoID string) { // Create reference if result.oldCommitID == gitShortEmptySha { + if tp == git.TagPrefix { + tp = "tag" + } else if tp == git.BranchPrefix { + tp = "branch" + } + commitID, err := gitRepo.GetRefCommitID(result.refName) + if err != nil { + log.Error("gitRepo.GetRefCommitID [repo_id: %s, ref_name: %s]: %v", m.RepoID, result.refName, err) + continue + } + notification.NotifySyncPushCommits(m.Repo.MustOwner(), m.Repo, result.refName, git.EmptySHA, commitID, repo_module.NewPushCommits()) notification.NotifySyncCreateRef(m.Repo.MustOwner(), m.Repo, tp, result.refName) continue }