Skip to content

Commit 8efef06

Browse files
lunnytwenty-panda
authored andcommitted
fix(repository): git push to an adopted repository fails
Fix adopt repository has empty object name in database (go-gitea#31333) Fix go-gitea#31330 Fix go-gitea#31311 A workaround to fix the old database is to update object_format_name to `sha1` if it's empty or null. (cherry picked from commit 1968c22) With tests services/repository/adopt_test.go
1 parent c984e62 commit 8efef06

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

modules/repository/branch.go

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func SyncRepoBranchesWithRepo(ctx context.Context, repo *repo_model.Repository,
4545
if err != nil {
4646
return 0, fmt.Errorf("UpdateRepository: %w", err)
4747
}
48+
repo.ObjectFormatName = objFmt.Name() // keep consistent with db
4849

4950
allBranches := container.Set[string]{}
5051
{

release-notes/8.0.0/fix/4149.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
git push to an adopted repository fails

services/repository/adopt_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ import (
1010

1111
"code.gitea.io/gitea/models/db"
1212
"code.gitea.io/gitea/models/unittest"
13+
user_model "code.gitea.io/gitea/models/user"
14+
"code.gitea.io/gitea/modules/git"
1315
"code.gitea.io/gitea/modules/setting"
1416

1517
"github.com/stretchr/testify/assert"
18+
"github.com/stretchr/testify/require"
1619
)
1720

1821
func TestCheckUnadoptedRepositories_Add(t *testing.T) {
@@ -83,3 +86,30 @@ func TestListUnadoptedRepositories_ListOptions(t *testing.T) {
8386
assert.Equal(t, 2, count)
8487
assert.Equal(t, unadoptedList[1], repoNames[0])
8588
}
89+
90+
func TestAdoptRepository(t *testing.T) {
91+
assert.NoError(t, unittest.PrepareTestDatabase())
92+
username := "user2"
93+
94+
unadopted := "unadopted"
95+
assert.NoError(t, unittest.CopyDir(
96+
"../../modules/git/tests/repos/repo1_bare",
97+
path.Join(setting.RepoRootPath, username, unadopted+".git"),
98+
))
99+
100+
opts := db.ListOptions{Page: 1, PageSize: 1}
101+
repoNames, _, err := ListUnadoptedRepositories(db.DefaultContext, "", &opts)
102+
require.NoError(t, err)
103+
require.Contains(t, repoNames, path.Join(username, unadopted))
104+
105+
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
106+
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
107+
repo, err := AdoptRepository(db.DefaultContext, doer, owner, CreateRepoOptions{
108+
Name: unadopted,
109+
Description: "description",
110+
IsPrivate: false,
111+
AutoInit: true,
112+
})
113+
assert.NoError(t, err)
114+
assert.Equal(t, git.Sha1ObjectFormat.Name(), repo.ObjectFormatName)
115+
}

0 commit comments

Comments
 (0)