aboutsummaryrefslogtreecommitdiffstats
path: root/modules/middleware
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-08-08 22:43:14 +0800
committerUnknwon <u@gogs.io>2015-08-08 22:43:14 +0800
commitdea3a8c6a42ea7e4921c0e4beee5d4fd0437dbe5 (patch)
tree773b28a72cee24e4a02f3d162de8a37a8f912f59 /modules/middleware
parentd015d951bd6959f9585d8a83acfe7bba07b7eaad (diff)
downloadgitea-dea3a8c6a42ea7e4921c0e4beee5d4fd0437dbe5.tar.gz
gitea-dea3a8c6a42ea7e4921c0e4beee5d4fd0437dbe5.zip
WIP: create PR - choose branch
Diffstat (limited to 'modules/middleware')
-rw-r--r--modules/middleware/repo.go42
1 files changed, 33 insertions, 9 deletions
diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go
index 1216463243..c4c53c03a2 100644
--- a/modules/middleware/repo.go
+++ b/modules/middleware/repo.go
@@ -257,7 +257,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
ctx.Data["HasAccess"] = true
if repo.IsMirror {
- ctx.Repo.Mirror, err = models.GetMirror(repo.Id)
+ ctx.Repo.Mirror, err = models.GetMirror(repo.ID)
if err != nil {
ctx.Handle(500, "GetMirror", err)
return
@@ -291,10 +291,34 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
ctx.Data["Tags"] = tags
ctx.Repo.Repository.NumTags = len(tags)
- // Non-fork repository will not return error in this method.
- if err = repo.GetForkRepo(); err != nil {
- ctx.Handle(500, "GetForkRepo", err)
- return
+ if repo.IsFork {
+ // Non-fork repository will not return error in this method.
+ if err = repo.GetBaseRepo(); err != nil {
+ ctx.Handle(500, "GetBaseRepo", err)
+ return
+ } else if repo.BaseRepo.GetOwner(); err != nil {
+ ctx.Handle(500, "BaseRepo.GetOwner", err)
+ return
+ }
+
+ bsaeRepo := repo.BaseRepo
+ baseGitRepo, err := git.OpenRepository(models.RepoPath(bsaeRepo.Owner.Name, bsaeRepo.Name))
+ if err != nil {
+ ctx.Handle(500, "OpenRepository", err)
+ return
+ }
+ if len(bsaeRepo.DefaultBranch) > 0 && baseGitRepo.IsBranchExist(bsaeRepo.DefaultBranch) {
+ ctx.Data["BaseDefaultBranch"] = bsaeRepo.DefaultBranch
+ } else {
+ baseBranches, err := baseGitRepo.GetBranches()
+ if err != nil {
+ ctx.Handle(500, "GetBranches", err)
+ return
+ }
+ if len(baseBranches) > 0 {
+ ctx.Data["BaseDefaultBranch"] = baseBranches[0]
+ }
+ }
}
ctx.Data["Title"] = u.Name + "/" + repo.Name
@@ -327,8 +351,8 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
}
if ctx.IsSigned {
- ctx.Data["IsWatchingRepo"] = models.IsWatching(ctx.User.Id, repo.Id)
- ctx.Data["IsStaringRepo"] = models.IsStaring(ctx.User.Id, repo.Id)
+ ctx.Data["IsWatchingRepo"] = models.IsWatching(ctx.User.Id, repo.ID)
+ ctx.Data["IsStaringRepo"] = models.IsStaring(ctx.User.Id, repo.ID)
}
ctx.Data["TagName"] = ctx.Repo.TagName
@@ -342,8 +366,8 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
// If not branch selected, try default one.
// If default branch doesn't exists, fall back to some other branch.
- if ctx.Repo.BranchName == "" {
- if ctx.Repo.Repository.DefaultBranch != "" && gitRepo.IsBranchExist(ctx.Repo.Repository.DefaultBranch) {
+ if len(ctx.Repo.BranchName) == 0 {
+ if len(ctx.Repo.Repository.DefaultBranch) > 0 && gitRepo.IsBranchExist(ctx.Repo.Repository.DefaultBranch) {
ctx.Repo.BranchName = ctx.Repo.Repository.DefaultBranch
} else if len(brs) > 0 {
ctx.Repo.BranchName = brs[0]