From 67d7e78fa316fb8aab12d934f5c066885d3f3557 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Mon, 22 May 2023 17:46:07 +0800 Subject: [PATCH 1/4] fix missing ref prefix when sync mirror --- services/mirror/mirror_pull.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index 60699294c18bd..d5c6e8317e0c4 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -142,6 +142,9 @@ func parseRemoteUpdateOutput(output string) []*mirrorSyncResult { log.Error("Expect two SHAs but not what found: %q", lines[i]) continue } + if !strings.HasPrefix(refName, git.BranchPrefix) { + refName = git.BranchPrefix + refName + } results = append(results, &mirrorSyncResult{ refName: refName, oldCommitID: shas[0], From 33f817adda7087d437062e352306e68132759e9d Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Tue, 23 May 2023 10:16:30 +0800 Subject: [PATCH 2/4] fix missing ref prefix when sync mirror --- services/mirror/mirror_pull.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index d5c6e8317e0c4..7f85ad944805a 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -142,11 +142,8 @@ func parseRemoteUpdateOutput(output string) []*mirrorSyncResult { log.Error("Expect two SHAs but not what found: %q", lines[i]) continue } - if !strings.HasPrefix(refName, git.BranchPrefix) { - refName = git.BranchPrefix + refName - } results = append(results, &mirrorSyncResult{ - refName: refName, + refName: git.BranchPrefix + refName, // the reference name of commits should also has prefix. oldCommitID: shas[0], newCommitID: shas[1], }) From cb5fd5c6dce2fb51c2ad86099a3ffb99ed128059 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Wed, 24 May 2023 11:56:20 +0800 Subject: [PATCH 3/4] add tests --- services/mirror/mirror_pull_test.go | 82 +++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 services/mirror/mirror_pull_test.go diff --git a/services/mirror/mirror_pull_test.go b/services/mirror/mirror_pull_test.go new file mode 100644 index 0000000000000..ee25c72b54874 --- /dev/null +++ b/services/mirror/mirror_pull_test.go @@ -0,0 +1,82 @@ +package mirror + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestParseRemoteUpdateOutput(t *testing.T) { + tests := []struct { + input string + results []*mirrorSyncResult + }{ + { + // create tag + input: "From https://xxx.com/xxx/xxx\n * [new tag] v1.4 -> v1.4\n", + results: []*mirrorSyncResult{ + { + refName: "refs/tags/v1.4", + oldCommitID: gitShortEmptySha, + newCommitID: "", + }, + }, + }, + { + // delete tag and create branch + input: "From https://xxx.com/xxx/xxx\n - [deleted] (none) -> v1.0.1\n * [new branch] test/t3 -> test/t3\n * [new branch] test/t4 -> test/t4\n", + results: []*mirrorSyncResult{ + { + refName: "v1.0.1", + oldCommitID: "", + newCommitID: gitShortEmptySha, + }, + { + refName: "refs/heads/test/t3", + oldCommitID: gitShortEmptySha, + newCommitID: "", + }, + { + refName: "refs/heads/test/t4", + oldCommitID: gitShortEmptySha, + newCommitID: "", + }, + }, + }, + { + // delete branch + input: "From https://xxx.com/xxx/xxx\n - [deleted] (none) -> test/t2\n", + results: []*mirrorSyncResult{ + { + refName: "test/t2", + oldCommitID: "", + newCommitID: gitShortEmptySha, + }, + }, + }, + { + // new commits + input: "From https://xxx.com/xxx/xxx\n aeb77a8..425ec44 test/t3 -> test/t3\n 93b2801..3e1d4c2 test/t4 -> test/t4\n", + results: []*mirrorSyncResult{ + { + refName: "refs/heads/test/t3", + oldCommitID: "aeb77a8", + newCommitID: "425ec44", + }, + { + refName: "refs/heads/test/t4", + oldCommitID: "93b2801", + newCommitID: "3e1d4c2", + }, + }, + }, + } + + for _, test := range tests { + t.Run(test.input, func(t *testing.T) { + results := parseRemoteUpdateOutput(test.input) + assert.EqualValues(t, test.results, results, fmt.Sprintf("%#v", results)) + }) + } +} From cbd32ceb645da4c98b92f44712d66424a9400a11 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Wed, 24 May 2023 12:15:27 +0800 Subject: [PATCH 4/4] copyright --- services/mirror/mirror_pull_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/mirror/mirror_pull_test.go b/services/mirror/mirror_pull_test.go index ee25c72b54874..a0b89ec813792 100644 --- a/services/mirror/mirror_pull_test.go +++ b/services/mirror/mirror_pull_test.go @@ -1,3 +1,5 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT package mirror import (