From 88c363f933be9219574954061c054e40f77e5872 Mon Sep 17 00:00:00 2001 From: Ethan Koenig Date: Wed, 20 Dec 2017 00:21:10 -0800 Subject: [PATCH] Fix repo-transfer-and-team-repo-count bug (#3241) (#3244) --- models/repo.go | 14 -------------- models/repo_test.go | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/models/repo.go b/models/repo.go index c570acd6f..ff8b2a6a1 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1501,20 +1501,6 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error // Remove old team-repository relations. if owner.IsOrganization() { - if err = owner.getTeams(sess); err != nil { - return fmt.Errorf("getTeams: %v", err) - } - for _, t := range owner.Teams { - if !t.hasRepository(sess, repo.ID) { - continue - } - - t.NumRepos-- - if _, err := sess.ID(t.ID).Cols("num_repos").Update(t); err != nil { - return fmt.Errorf("decrease team repository count '%d': %v", t.ID, err) - } - } - if err = owner.removeOrgRepo(sess, repo.ID); err != nil { return fmt.Errorf("removeOrgRepo: %v", err) } diff --git a/models/repo_test.go b/models/repo_test.go index 34eaa16c0..752ffc2dd 100644 --- a/models/repo_test.go +++ b/models/repo_test.go @@ -153,3 +153,26 @@ func TestRepoLocalCopyPath(t *testing.T) { setting.Repository.Local.LocalCopyPath = tempPath assert.Equal(t, expected, repo.LocalCopyPath()) } + +func TestTransferOwnership(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + + doer := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + repo := AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) + repo.Owner = AssertExistsAndLoadBean(t, &User{ID: repo.OwnerID}).(*User) + assert.NoError(t, TransferOwnership(doer, "user2", repo)) + + transferredRepo := AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) + assert.EqualValues(t, 2, transferredRepo.OwnerID) + + assert.False(t, com.IsExist(RepoPath("user3", "repo3"))) + assert.True(t, com.IsExist(RepoPath("user2", "repo3"))) + AssertExistsAndLoadBean(t, &Action{ + OpType: ActionTransferRepo, + ActUserID: 2, + RepoID: 3, + Content: "user3/repo3", + }) + + CheckConsistencyFor(t, &Repository{}, &User{}, &Team{}) +}