From d6c9e3413a982fd64a74e774d4a2b8157f39f299 Mon Sep 17 00:00:00 2001 From: slene Date: Sun, 30 Mar 2014 13:30:17 +0800 Subject: [PATCH] fix display bare repo --- modules/middleware/repo.go | 96 +++++++++++++++++++-------------- routers/repo/repo.go | 1 + templates/repo/single_bare.tmpl | 13 ++--- templates/repo/toolbar.tmpl | 2 +- web.go | 13 ++--- 5 files changed, 72 insertions(+), 53 deletions(-) diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index deb282865..559e90c0c 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -17,10 +17,20 @@ import ( "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) { - // assign false first - ctx.Data["IsRepositoryValid"] = false + // valid brachname + 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 ( user *models.User @@ -71,6 +81,8 @@ func RepoAssignment(redirect bool) martini.Handler { } ctx.Repo.Repository = repo + ctx.Data["IsBareRepo"] = ctx.Repo.Repository.IsBare + gitRepo, err := git.OpenRepository(models.RepoPath(userName, repoName)) if err != nil { 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["RepoLink"] = ctx.Repo.RepoLink 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.HTTPS = fmt.Sprintf("%s%s/%s.git", base.AppUrl, user.LowerName, repo.LowerName) ctx.Data["CloneLink"] = ctx.Repo.CloneLink - if repo.IsBare { - ctx.Data["IsBareRepo"] = true - ctx.HTML(200, "repo/single_bare") - return + // when repo is bare, not valid branch + if !ctx.Repo.Repository.IsBare && validBranch { + detect: + if len(branchName) > 0 { + // TODO check tag + if models.IsBranchExist(user.Name, repoName, branchName) { + ctx.Repo.IsBranch = true + ctx.Repo.BranchName = branchName + + ctx.Repo.Commit, err = gitRepo.GetCommitOfBranch(branchName) + if err != nil { + ctx.Handle(404, "RepoAssignment invalid branch", nil) + 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 { + ctx.Handle(404, "RepoAssignment invalid repo", nil) + return + } + + } else { + branchName = "master" + goto detect + } } - detect: - if len(branchName) > 0 { - // TODO check tag - if models.IsBranchExist(user.Name, repoName, branchName) { - ctx.Repo.IsBranch = true - ctx.Repo.BranchName = branchName - - ctx.Repo.Commit, err = gitRepo.GetCommitOfBranch(branchName) - if err != nil { - ctx.Handle(404, "RepoAssignment invalid branch", nil) - 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 { - ctx.Handle(404, "RepoAssignment invalid repo", nil) - return - } - - } else { - branchName = "master" - goto detect + // repo is bare and display enable + if displayBare && ctx.Repo.Repository.IsBare { + ctx.HTML(200, "repo/single_bare") + return } if ctx.IsSigned { diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 27c806a3b..5b0a165d5 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -78,6 +78,7 @@ func Single(ctx *middleware.Context, params martini.Params) { ctx.Handle(404, "repo.Single(GetBranches)", err) return } + ctx.Data["Branches"] = brs isViewBranch := ctx.Repo.IsBranch diff --git a/templates/repo/single_bare.tmpl b/templates/repo/single_bare.tmpl index fe0e3aa35..035e78e8b 100644 --- a/templates/repo/single_bare.tmpl +++ b/templates/repo/single_bare.tmpl @@ -1,6 +1,7 @@ {{template "base/head" .}} {{template "base/navbar" .}} {{template "repo/nav" .}} +{{template "repo/toolbar" .}}
@@ -23,15 +24,15 @@

Create a new repository on the command line

touch README.md
-        git init
-        git add README.md
-        git commit -m "first commit"
-        git remote add origin 
-        git push -u origin master
+git init +git add README.md +git commit -m "first commit" +git remote add origin +git push -u origin master

Push an existing repository from the command line

git remote add origin 
-        git push -u origin master
+git push -u origin master
diff --git a/templates/repo/toolbar.tmpl b/templates/repo/toolbar.tmpl index 3c7c8a50e..542f8fd86 100644 --- a/templates/repo/toolbar.tmpl +++ b/templates/repo/toolbar.tmpl @@ -3,7 +3,7 @@