diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-02-14 22:14:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-14 22:14:29 +0800 |
commit | 3a91ac51a93aa6e352896048ce37c01227b42055 (patch) | |
tree | d4b63085ff9a79495ba99d872e4afdb72727fe0c /models/repo.go | |
parent | d67b278a0d05e122bf510ac52bfbd69eab4f654d (diff) | |
download | gitea-3a91ac51a93aa6e352896048ce37c01227b42055.tar.gz gitea-3a91ac51a93aa6e352896048ce37c01227b42055.zip |
fix bug of multiple forks (#928)
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/models/repo.go b/models/repo.go index d83c5fd6ab..97bad686b9 100644 --- a/models/repo.go +++ b/models/repo.go @@ -2372,6 +2372,17 @@ func HasForkedRepo(ownerID, repoID int64) (*Repository, bool) { // ForkRepository forks a repository func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Repository, err error) { + forkedRepo, err := oldRepo.GetUserFork(u.ID) + if err != nil { + return nil, err + } + if forkedRepo != nil { + return nil, ErrRepoAlreadyExist{ + Uname: u.Name, + Name: forkedRepo.Name, + } + } + repo := &Repository{ OwnerID: u.ID, Owner: u, @@ -2453,6 +2464,19 @@ func (repo *Repository) GetForks() ([]*Repository, error) { return forks, x.Find(&forks, &Repository{ForkID: repo.ID}) } +// GetUserFork return user forked repository from this repository, if not forked return nil +func (repo *Repository) GetUserFork(userID int64) (*Repository, error) { + var forkedRepo Repository + has, err := x.Where("fork_id = ?", repo.ID).And("owner_id = ?", userID).Get(&forkedRepo) + if err != nil { + return nil, err + } + if !has { + return nil, nil + } + return &forkedRepo, nil +} + // __________ .__ // \______ \____________ ____ ____ | |__ // | | _/\_ __ \__ \ / \_/ ___\| | \ |