Browse Source

repo: fix panic on pull request submit (#4572)

pull/4633/head
Unknwon 8 years ago
parent
commit
e02fac4968
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 2
      gogs.go
  2. 9
      models/repo.go
  3. 2
      models/user.go
  4. 16
      routes/repo/pull.go
  5. 2
      templates/.VERSION

2
gogs.go

@ -16,7 +16,7 @@ import (
"github.com/gogits/gogs/pkg/setting"
)
const APP_VER = "0.11.25.0714"
const APP_VER = "0.11.26.0714"
func init() {
setting.AppVer = APP_VER

9
models/repo.go

@ -2257,10 +2257,13 @@ func (repo *Repository) GetStargazers(page int) ([]*User, error) {
// HasForkedRepo checks if given user has already forked a repository.
// When user has already forked, it returns true along with the repository.
func HasForkedRepo(ownerID, repoID int64) (*Repository, bool) {
func HasForkedRepo(ownerID, repoID int64) (*Repository, bool, error) {
repo := new(Repository)
has, _ := x.Where("owner_id = ? AND fork_id = ?", ownerID, repoID).Get(repo)
return repo, has
has, err := x.Where("owner_id = ? AND fork_id = ?", ownerID, repoID).Get(repo)
if err != nil {
return nil, false, err
}
return repo, has, repo.LoadAttributes()
}
// ForkRepository creates a fork of target repository under another user domain.

2
models/user.go

@ -137,7 +137,7 @@ func (u *User) IsLocal() bool {
// HasForkedRepo checks if user has already forked a repository with given ID.
func (u *User) HasForkedRepo(repoID int64) bool {
_, has := HasForkedRepo(u.ID, repoID)
_, has, _ := HasForkedRepo(u.ID, repoID)
return has
}

16
routes/repo/pull.go

@ -101,8 +101,11 @@ func ForkPost(c *context.Context, f form.CreateRepo) {
return
}
repo, has := models.HasForkedRepo(ctxUser.ID, baseRepo.ID)
if has {
repo, has, err := models.HasForkedRepo(ctxUser.ID, baseRepo.ID)
if err != nil {
c.ServerError("HasForkedRepo", err)
return
} else if has {
c.Redirect(repo.Link())
return
}
@ -119,7 +122,7 @@ func ForkPost(c *context.Context, f form.CreateRepo) {
return
}
repo, err := models.ForkRepository(c.User, ctxUser, baseRepo, f.RepoName, f.Description)
repo, err = models.ForkRepository(c.User, ctxUser, baseRepo, f.RepoName, f.Description)
if err != nil {
c.Data["Err_RepoName"] = true
switch {
@ -475,8 +478,11 @@ func ParseCompareInfo(c *context.Context) (*models.User, *models.Repository, *gi
// no need to check the fork relation.
if !isSameRepo {
var has bool
headRepo, has = models.HasForkedRepo(headUser.ID, baseRepo.ID)
if !has {
headRepo, has, err = models.HasForkedRepo(headUser.ID, baseRepo.ID)
if err != nil {
c.ServerError("HasForkedRepo", err)
return nil, nil, nil, nil, "", ""
} else if !has {
log.Trace("ParseCompareInfo [base_repo_id: %d]: does not have fork or in same repository", baseRepo.ID)
c.NotFound()
return nil, nil, nil, nil, "", ""

2
templates/.VERSION

@ -1 +1 @@
0.11.25.0714
0.11.26.0714
Loading…
Cancel
Save