|
|
@ -17,10 +17,20 @@ import ( |
|
|
|
"github.com/gogits/gogs/modules/base" |
|
|
|
"github.com/gogits/gogs/modules/base" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func RepoAssignment(redirect bool) martini.Handler { |
|
|
|
func RepoAssignment(redirect bool, args ...bool) martini.Handler { |
|
|
|
return func(ctx *Context, params martini.Params) { |
|
|
|
return func(ctx *Context, params martini.Params) { |
|
|
|
// assign false first
|
|
|
|
// valid brachname
|
|
|
|
ctx.Data["IsRepositoryValid"] = false |
|
|
|
var validBranch bool |
|
|
|
|
|
|
|
// display bare quick start if it is a bare repo
|
|
|
|
|
|
|
|
var displayBare bool |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(args) >= 1 { |
|
|
|
|
|
|
|
validBranch = args[0] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(args) >= 2 { |
|
|
|
|
|
|
|
displayBare = args[1] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
var ( |
|
|
|
user *models.User |
|
|
|
user *models.User |
|
|
@ -71,6 +81,8 @@ func RepoAssignment(redirect bool) martini.Handler { |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Repo.Repository = repo |
|
|
|
ctx.Repo.Repository = repo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["IsBareRepo"] = ctx.Repo.Repository.IsBare |
|
|
|
|
|
|
|
|
|
|
|
gitRepo, err := git.OpenRepository(models.RepoPath(userName, repoName)) |
|
|
|
gitRepo, err := git.OpenRepository(models.RepoPath(userName, repoName)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Handle(404, "RepoAssignment Invalid repo "+models.RepoPath(userName, repoName), err) |
|
|
|
ctx.Handle(404, "RepoAssignment Invalid repo "+models.RepoPath(userName, repoName), err) |
|
|
@ -86,50 +98,54 @@ func RepoAssignment(redirect bool) martini.Handler { |
|
|
|
ctx.Data["Owner"] = user |
|
|
|
ctx.Data["Owner"] = user |
|
|
|
ctx.Data["RepoLink"] = ctx.Repo.RepoLink |
|
|
|
ctx.Data["RepoLink"] = ctx.Repo.RepoLink |
|
|
|
ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner |
|
|
|
ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner |
|
|
|
|
|
|
|
ctx.Data["BranchName"] = "" |
|
|
|
|
|
|
|
|
|
|
|
ctx.Repo.CloneLink.SSH = fmt.Sprintf("%s@%s:%s/%s.git", base.RunUser, base.Domain, user.LowerName, repo.LowerName) |
|
|
|
ctx.Repo.CloneLink.SSH = fmt.Sprintf("%s@%s:%s/%s.git", base.RunUser, base.Domain, user.LowerName, repo.LowerName) |
|
|
|
ctx.Repo.CloneLink.HTTPS = fmt.Sprintf("%s%s/%s.git", base.AppUrl, user.LowerName, repo.LowerName) |
|
|
|
ctx.Repo.CloneLink.HTTPS = fmt.Sprintf("%s%s/%s.git", base.AppUrl, user.LowerName, repo.LowerName) |
|
|
|
ctx.Data["CloneLink"] = ctx.Repo.CloneLink |
|
|
|
ctx.Data["CloneLink"] = ctx.Repo.CloneLink |
|
|
|
|
|
|
|
|
|
|
|
if repo.IsBare { |
|
|
|
// when repo is bare, not valid branch
|
|
|
|
ctx.Data["IsBareRepo"] = true |
|
|
|
if !ctx.Repo.Repository.IsBare && validBranch { |
|
|
|
ctx.HTML(200, "repo/single_bare") |
|
|
|
detect: |
|
|
|
return |
|
|
|
if len(branchName) > 0 { |
|
|
|
} |
|
|
|
// TODO check tag
|
|
|
|
|
|
|
|
if models.IsBranchExist(user.Name, repoName, branchName) { |
|
|
|
detect: |
|
|
|
ctx.Repo.IsBranch = true |
|
|
|
if len(branchName) > 0 { |
|
|
|
ctx.Repo.BranchName = branchName |
|
|
|
// TODO check tag
|
|
|
|
|
|
|
|
if models.IsBranchExist(user.Name, repoName, branchName) { |
|
|
|
ctx.Repo.Commit, err = gitRepo.GetCommitOfBranch(branchName) |
|
|
|
ctx.Repo.IsBranch = true |
|
|
|
if err != nil { |
|
|
|
ctx.Repo.BranchName = branchName |
|
|
|
ctx.Handle(404, "RepoAssignment invalid branch", nil) |
|
|
|
|
|
|
|
return |
|
|
|
ctx.Repo.Commit, err = gitRepo.GetCommitOfBranch(branchName) |
|
|
|
} |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.Handle(404, "RepoAssignment invalid branch", nil) |
|
|
|
ctx.Repo.CommitId = ctx.Repo.Commit.Oid.String() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if len(branchName) == 40 { |
|
|
|
|
|
|
|
ctx.Repo.IsCommit = true |
|
|
|
|
|
|
|
ctx.Repo.CommitId = branchName |
|
|
|
|
|
|
|
ctx.Repo.BranchName = branchName |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Repo.Commit, err = gitRepo.GetCommit(branchName) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.Handle(404, "RepoAssignment invalid commit", nil) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
ctx.Handle(404, "RepoAssignment invalid repo", nil) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ctx.Repo.CommitId = ctx.Repo.Commit.Oid.String() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if len(branchName) == 40 { |
|
|
|
|
|
|
|
ctx.Repo.IsCommit = true |
|
|
|
|
|
|
|
ctx.Repo.CommitId = branchName |
|
|
|
|
|
|
|
ctx.Repo.BranchName = branchName |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Repo.Commit, err = gitRepo.GetCommit(branchName) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.Handle(404, "RepoAssignment invalid commit", nil) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ctx.Handle(404, "RepoAssignment invalid repo", nil) |
|
|
|
branchName = "master" |
|
|
|
return |
|
|
|
goto detect |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
// repo is bare and display enable
|
|
|
|
branchName = "master" |
|
|
|
if displayBare && ctx.Repo.Repository.IsBare { |
|
|
|
goto detect |
|
|
|
ctx.HTML(200, "repo/single_bare") |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ctx.IsSigned { |
|
|
|
if ctx.IsSigned { |
|
|
|