mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 03:25:11 +01:00 
			
		
		
		
	fix bug of multiple forks (#928)
This commit is contained in:
		
							parent
							
								
									d67b278a0d
								
							
						
					
					
						commit
						3a91ac51a9
					
				| @ -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 | ||||
| } | ||||
| 
 | ||||
| // __________                             .__ | ||||
| // \______   \____________    ____   ____ |  |__ | ||||
| //  |    |  _/\_  __ \__  \  /    \_/ ___\|  |  \ | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user