From 578d981d7e196728dc0685f62a211383d4c808fa Mon Sep 17 00:00:00 2001
From: slene <vslene@gmail.com>
Date: Sun, 30 Mar 2014 11:38:41 +0800
Subject: [PATCH] display bare repo page

---
 modules/middleware/repo.go      | 32 ++++++++++------
 routers/repo/repo.go            | 10 -----
 templates/repo/single.tmpl      |  4 --
 templates/repo/single_bare.tmpl | 66 ++++++++++++++++++---------------
 4 files changed, 57 insertions(+), 55 deletions(-)

diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go
index d1b68b052..deb282865 100644
--- a/modules/middleware/repo.go
+++ b/modules/middleware/repo.go
@@ -73,11 +73,30 @@ func RepoAssignment(redirect bool) martini.Handler {
 
 		gitRepo, err := git.OpenRepository(models.RepoPath(userName, repoName))
 		if err != nil {
-			ctx.Handle(404, "RepoAssignment Invalid repo", err)
+			ctx.Handle(404, "RepoAssignment Invalid repo "+models.RepoPath(userName, repoName), err)
 			return
 		}
 		ctx.Repo.GitRepo = gitRepo
 
+		ctx.Repo.Owner = user
+		ctx.Repo.RepoLink = "/" + user.Name + "/" + repo.Name
+
+		ctx.Data["Title"] = user.Name + "/" + repo.Name
+		ctx.Data["Repository"] = repo
+		ctx.Data["Owner"] = user
+		ctx.Data["RepoLink"] = ctx.Repo.RepoLink
+		ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner
+
+		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
+		}
+
 	detect:
 		if len(branchName) > 0 {
 			// TODO check tag
@@ -117,19 +136,8 @@ func RepoAssignment(redirect bool) martini.Handler {
 			ctx.Repo.IsWatching = models.IsWatching(ctx.User.Id, repo.Id)
 		}
 
-		ctx.Repo.Owner = user
-		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.RepoLink = "/" + user.Name + "/" + repo.Name
-
 		ctx.Data["BranchName"] = ctx.Repo.BranchName
 		ctx.Data["CommitId"] = ctx.Repo.CommitId
-		ctx.Data["Repository"] = repo
-		ctx.Data["Owner"] = user
-		ctx.Data["Title"] = user.Name + "/" + repo.Name
-		ctx.Data["CloneLink"] = ctx.Repo.CloneLink
-		ctx.Data["RepoLink"] = ctx.Repo.RepoLink
-		ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner
 		ctx.Data["IsRepositoryWatching"] = ctx.Repo.IsWatching
 	}
 }
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index c9c9af1e4..27c806a3b 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -77,10 +77,6 @@ func Single(ctx *middleware.Context, params martini.Params) {
 	if err != nil {
 		ctx.Handle(404, "repo.Single(GetBranches)", err)
 		return
-	} else if ctx.Repo.Repository.IsBare {
-		ctx.Data["IsBareRepo"] = true
-		ctx.HTML(200, "repo/single")
-		return
 	}
 	ctx.Data["Branches"] = brs
 
@@ -264,12 +260,6 @@ func Setting(ctx *middleware.Context, params martini.Params) {
 
 	ctx.Data["IsRepoToolbarSetting"] = true
 
-	if ctx.Repo.Repository.IsBare {
-		ctx.Data["IsBareRepo"] = true
-		ctx.HTML(200, "repo/setting")
-		return
-	}
-
 	var title string
 	if t, ok := ctx.Data["Title"].(string); ok {
 		title = t
diff --git a/templates/repo/single.tmpl b/templates/repo/single.tmpl
index abaa4e893..0bf7b0aaf 100644
--- a/templates/repo/single.tmpl
+++ b/templates/repo/single.tmpl
@@ -4,9 +4,6 @@
 {{template "repo/toolbar" .}}
 <div id="body" class="container">
     <div id="source">
-        {{if .IsBareRepo}}
-        {{template "repo/single_bare" .}}
-        {{else}}
         <div class="source-toolbar">
             {{ $n := len .Treenames}}
             {{if not .IsFile}}<button class="btn btn-default pull-right hidden"><i class="fa fa-plus-square"></i>Add File</button>{{end}}
@@ -38,7 +35,6 @@
         {{else}}
             {{template "repo/single_list" .}}
         {{end}}
-        {{end}}
     </div>
 </div>
 {{template "base/footer" .}}
diff --git a/templates/repo/single_bare.tmpl b/templates/repo/single_bare.tmpl
index ed182ad28..fe0e3aa35 100644
--- a/templates/repo/single_bare.tmpl
+++ b/templates/repo/single_bare.tmpl
@@ -1,31 +1,39 @@
-<div class="panel panel-default guide-box clone-group-btn">
-    <div class="panel-heading guide-head">
-        <h4>Quick Guide</h4>
-    </div>
-    <div class="panel-body guide-content text-center">
-        <h3>Clone this repository</h3>
-        <div class="input-group col-md-8 col-md-offset-2 guide-buttons">
-            <span class="input-group-btn">
-                <button class="btn btn-default" data-link="{{.CloneLink.SSH}}" type="button">SSH</button>
-                <button class="btn btn-default" data-link="{{.CloneLink.HTTPS}}" type="button">HTTPS</button>
-            </span>
-            <input type="text" class="form-control clone-group-url" id="guide-clone-url" value="" readonly/>
-            <span class="input-group-btn">
-                <button class="btn btn-default" type="button"><i class="fa fa-copy" data-toggle="tooltip" title="copy to clipboard" data-placement="top"></i></button>
-            </span>
+{{template "base/head" .}}
+{{template "base/navbar" .}}
+{{template "repo/nav" .}}
+<div id="body" class="container">
+    <div id="source">
+        <div class="panel panel-default guide-box clone-group-btn">
+            <div class="panel-heading guide-head">
+                <h4>Quick Guide</h4>
+            </div>
+            <div class="panel-body guide-content text-center">
+                <h3>Clone this repository</h3>
+                <div class="input-group col-md-8 col-md-offset-2 guide-buttons">
+                    <span class="input-group-btn">
+                        <button class="btn btn-default" data-link="{{.CloneLink.SSH}}" type="button">SSH</button>
+                        <button class="btn btn-default" data-link="{{.CloneLink.HTTPS}}" type="button">HTTPS</button>
+                    </span>
+                    <input type="text" class="form-control clone-group-url" id="guide-clone-url" value="" readonly/>
+                    <span class="input-group-btn">
+                        <button class="btn btn-default" type="button"><i class="fa fa-copy" data-toggle="tooltip" title="copy to clipboard" data-placement="top"></i></button>
+                    </span>
+                </div>
+                <p>We recommend every repository include a <strong>README</strong>, <strong>LICENSE</strong>, and <strong>.gitignore</strong>.</p>
+                <hr/>
+                <h3>Create a new repository on the command line</h3>
+                    <pre class="text-left"><code>touch README.md
+        git init
+        git add README.md
+        git commit -m "first commit"
+        git remote add origin <span class="clone-url"></span>
+        git push -u origin master</code></pre>
+                <hr/>
+                <h3>Push an existing repository from the command line</h3>
+                <pre class="text-left"><code>git remote add origin <span class="clone-url"></span>
+        git push -u origin master</code></pre>
+            </div>
         </div>
-        <p>We recommend every repository include a <strong>README</strong>, <strong>LICENSE</strong>, and <strong>.gitignore</strong>.</p>
-        <hr/>
-        <h3>Create a new repository on the command line</h3>
-            <pre class="text-left"><code>touch README.md
-git init
-git add README.md
-git commit -m "first commit"
-git remote add origin <span class="clone-url"></span>
-git push -u origin master</code></pre>
-        <hr/>
-        <h3>Push an existing repository from the command line</h3>
-        <pre class="text-left"><code>git remote add origin <span class="clone-url"></span>
-git push -u origin master</code></pre>
     </div>
-</div>
\ No newline at end of file
+</div>
+{{template "base/footer" .}}