Skip to content

Commit 826b7b9

Browse files
authored
Fix missing reference prefix of commits when sync mirror repository (go-gitea#24994)
replace go-gitea#24868 just a patch to fix go-gitea#24824 in v1.19.4 The reference name of commits when synchronizing should also has prefix like refs/heads/<branch-name>.
1 parent 7dc46ff commit 826b7b9

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

services/mirror/mirror_pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func parseRemoteUpdateOutput(output string) []*mirrorSyncResult {
143143
continue
144144
}
145145
results = append(results, &mirrorSyncResult{
146-
refName: refName,
146+
refName: git.BranchPrefix + refName, // the reference name of commits should also has prefix.
147147
oldCommitID: shas[0],
148148
newCommitID: shas[1],
149149
})

services/mirror/mirror_pull_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
package mirror
4+
5+
import (
6+
"fmt"
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestParseRemoteUpdateOutput(t *testing.T) {
13+
tests := []struct {
14+
input string
15+
results []*mirrorSyncResult
16+
}{
17+
{
18+
// create tag
19+
input: "From https://xxx.com/xxx/xxx\n * [new tag] v1.4 -> v1.4\n",
20+
results: []*mirrorSyncResult{
21+
{
22+
refName: "refs/tags/v1.4",
23+
oldCommitID: gitShortEmptySha,
24+
newCommitID: "",
25+
},
26+
},
27+
},
28+
{
29+
// delete tag and create branch
30+
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",
31+
results: []*mirrorSyncResult{
32+
{
33+
refName: "v1.0.1",
34+
oldCommitID: "",
35+
newCommitID: gitShortEmptySha,
36+
},
37+
{
38+
refName: "refs/heads/test/t3",
39+
oldCommitID: gitShortEmptySha,
40+
newCommitID: "",
41+
},
42+
{
43+
refName: "refs/heads/test/t4",
44+
oldCommitID: gitShortEmptySha,
45+
newCommitID: "",
46+
},
47+
},
48+
},
49+
{
50+
// delete branch
51+
input: "From https://xxx.com/xxx/xxx\n - [deleted] (none) -> test/t2\n",
52+
results: []*mirrorSyncResult{
53+
{
54+
refName: "test/t2",
55+
oldCommitID: "",
56+
newCommitID: gitShortEmptySha,
57+
},
58+
},
59+
},
60+
{
61+
// new commits
62+
input: "From https://xxx.com/xxx/xxx\n aeb77a8..425ec44 test/t3 -> test/t3\n 93b2801..3e1d4c2 test/t4 -> test/t4\n",
63+
results: []*mirrorSyncResult{
64+
{
65+
refName: "refs/heads/test/t3",
66+
oldCommitID: "aeb77a8",
67+
newCommitID: "425ec44",
68+
},
69+
{
70+
refName: "refs/heads/test/t4",
71+
oldCommitID: "93b2801",
72+
newCommitID: "3e1d4c2",
73+
},
74+
},
75+
},
76+
}
77+
78+
for _, test := range tests {
79+
t.Run(test.input, func(t *testing.T) {
80+
results := parseRemoteUpdateOutput(test.input)
81+
assert.EqualValues(t, test.results, results, fmt.Sprintf("%#v", results))
82+
})
83+
}
84+
}

0 commit comments

Comments
 (0)