Skip to content

Commit 2c47b06

Browse files
GiteaBotlunnywxiaoguang
authored
Fix mirror bug (#33224) (#33225)
Backport #33224 by lunny Fix #33200 Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent 31f2a32 commit 2c47b06

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

modules/git/ref_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ func TestRefName(t *testing.T) {
2020

2121
// Test pull names
2222
assert.Equal(t, "1", RefName("refs/pull/1/head").PullName())
23+
assert.True(t, RefName("refs/pull/1/head").IsPull())
24+
assert.True(t, RefName("refs/pull/1/merge").IsPull())
2325
assert.Equal(t, "my/pull", RefName("refs/pull/my/pull/head").PullName())
2426

2527
// Test for branch names

services/mirror/mirror_pull.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ type mirrorSyncResult struct {
9797
/*
9898
// * [new tag] v0.1.8 -> v0.1.8
9999
// * [new branch] master -> origin/master
100+
// * [new ref] refs/pull/2/head -> refs/pull/2/head"
100101
// - [deleted] (none) -> origin/test // delete a branch
101102
// - [deleted] (none) -> 1 // delete a tag
102103
// 957a993..a87ba5f test -> origin/test
@@ -127,6 +128,11 @@ func parseRemoteUpdateOutput(output, remoteName string) []*mirrorSyncResult {
127128
refName: git.RefNameFromBranch(refName),
128129
oldCommitID: gitShortEmptySha,
129130
})
131+
case strings.HasPrefix(lines[i], " * [new ref]"): // new reference
132+
results = append(results, &mirrorSyncResult{
133+
refName: git.RefName(refName),
134+
oldCommitID: gitShortEmptySha,
135+
})
130136
case strings.HasPrefix(lines[i], " - "): // Delete reference
131137
isTag := !strings.HasPrefix(refName, remoteName+"/")
132138
var refFullName git.RefName
@@ -169,8 +175,15 @@ func parseRemoteUpdateOutput(output, remoteName string) []*mirrorSyncResult {
169175
log.Error("Expect two SHAs but not what found: %q", lines[i])
170176
continue
171177
}
178+
var refFullName git.RefName
179+
if strings.HasPrefix(refName, "refs/") {
180+
refFullName = git.RefName(refName)
181+
} else {
182+
refFullName = git.RefNameFromBranch(strings.TrimPrefix(refName, remoteName+"/"))
183+
}
184+
172185
results = append(results, &mirrorSyncResult{
173-
refName: git.RefNameFromBranch(strings.TrimPrefix(refName, remoteName+"/")),
186+
refName: refFullName,
174187
oldCommitID: shas[0],
175188
newCommitID: shas[1],
176189
})

0 commit comments

Comments
 (0)