From a55941ff833155cba88dbcc957b15c0ddcf07cb4 Mon Sep 17 00:00:00 2001
From: Unknown <joe2010xtmf@163.com>
Date: Fri, 28 Mar 2014 17:34:07 -0400
Subject: [PATCH] Add auto-detect home directory

---
 conf/app.ini              |  2 +-
 modules/base/conf.go      |  9 +++++++--
 routers/repo/issue.go     | 12 ++++++------
 templates/install.tmpl    |  2 +-
 templates/issue/view.tmpl | 18 ++++++++++--------
 5 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/conf/app.ini b/conf/app.ini
index a3c749be01..05c7745fc4 100644
--- a/conf/app.ini
+++ b/conf/app.ini
@@ -7,7 +7,7 @@ RUN_USER = git
 RUN_MODE = dev
 
 [repository]
-ROOT = /Users/%(RUN_USER)s/git/gogs-repositories
+ROOT = 
 LANG_IGNS = Google Go|C|C++|Python|Ruby|C Sharp
 LICENSES = Apache v2 License|GPL v2|MIT License|Affero GPL|Artistic License 2.0|BSD (3-Clause) License
 
diff --git a/modules/base/conf.go b/modules/base/conf.go
index b3a987e646..fd77cfd3ce 100644
--- a/modules/base/conf.go
+++ b/modules/base/conf.go
@@ -291,9 +291,14 @@ func NewConfigContext() {
 	PictureService = Cfg.MustValue("picture", "SERVICE")
 
 	// Determine and create root git reposiroty path.
-	RepoRootPath = Cfg.MustValue("repository", "ROOT")
+	homeDir, err := com.HomeDir()
+	if err != nil {
+		fmt.Printf("Fail to get home directory): %v\n", err)
+		os.Exit(2)
+	}
+	RepoRootPath = Cfg.MustValue("repository", "ROOT", filepath.Join(homeDir, "git/gogs-repositories"))
 	if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil {
-		fmt.Printf("models.init(fail to create RepoRootPath(%s)): %v\n", RepoRootPath, err)
+		fmt.Printf("Fail to create RepoRootPath(%s): %v\n", RepoRootPath, err)
 		os.Exit(2)
 	}
 }
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index c3d1a0d960..6ac8a53579 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -231,6 +231,12 @@ func Comment(ctx *middleware.Context, params martini.Params) {
 		return
 	}
 
+	content := ctx.Query("content")
+	if len(content) == 0 {
+		ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", ctx.User.Name, ctx.Repo.Repository.Name, index))
+		return
+	}
+
 	issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, int64(index))
 	if err != nil {
 		if err == models.ErrIssueNotExist {
@@ -241,12 +247,6 @@ func Comment(ctx *middleware.Context, params martini.Params) {
 		return
 	}
 
-	content := ctx.Query("content")
-	if len(content) == 0 {
-		ctx.Handle(404, "issue.Comment", err)
-		return
-	}
-
 	switch params["action"] {
 	case "new":
 		if err = models.CreateComment(ctx.User.Id, issue.Id, 0, 0, content); err != nil {
diff --git a/templates/install.tmpl b/templates/install.tmpl
index be5a69186d..872982a0ad 100644
--- a/templates/install.tmpl
+++ b/templates/install.tmpl
@@ -133,7 +133,7 @@
         <hr/>
 
         <div class="form-group text-center">
-            <!-- <button class="btn btn-primary btn-lg">Test Configuration</button> -->
+            <button class="btn btn-primary btn-lg">Test Configuration</button>
             <button class="btn btn-danger btn-lg">Install Gogs</button>
             <button class="btn btn-default btn-sm" type="button" data-toggle="modal" data-target="#advance-options-modal">
                 Advanced Options
diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl
index 609974f413..6f0a384800 100644
--- a/templates/issue/view.tmpl
+++ b/templates/issue/view.tmpl
@@ -11,7 +11,7 @@
                 <h1 class="title pull-left">{{.Issue.Name}}</h1>
                 <input id="issue-edit-title" class="form-control input-lg pull-left hidden" type="text" value="{issue.title}" data-ajax-rel="issue-save"/>
                 <p class="info pull-left">
-                    <a class="btn btn-default pull-right issue-edit" href="#" id="issue-edit-btn">Edit</a>
+                    <!-- <a class="btn btn-default pull-right issue-edit" href="#" id="issue-edit-btn">Edit</a> -->
                     <a class="btn btn-danger pull-right issue-edit-cancel hidden" href="#">Cancel</a>
                     <a class="btn btn-primary pull-right issue-edit-save hidden" href="#" data-ajax="{issue.save.link}" data-ajax-name="issue-save">Save</a>
                     <span class="status label label-{{if .Issue.IsClosed}}danger{{else}}success{{end}}">{{if .Issue.IsClosed}}Closed{{else}}Open{{end}}</span>
@@ -34,8 +34,8 @@
                    <div class="issue-content panel panel-default">
                        <div class="panel-heading">
                            <a href="/user/{{.Poster.Name}}" class="user">{{.Poster.Name}}</a> commented <span class="time">{{TimeSince .Created}}</span>
-                           <a class="issue-comment-del pull-right issue-action" href="#" title="Edit Comment"><i class="fa fa-times-circle"></i></a>
-                           <a class="issue-comment-edit pull-right issue-action" href="#" title="Remove Comment" data-url="{remove-link}"><i class="fa fa-edit"></i></a>
+                           <!-- <a class="issue-comment-del pull-right issue-action" href="#" title="Edit Comment"><i class="fa fa-times-circle"></i></a>
+                           <a class="issue-comment-edit pull-right issue-action" href="#" title="Remove Comment" data-url="{remove-link}"><i class="fa fa-edit"></i></a> -->
                            <span class="role label label-default pull-right">Owner</span>
                        </div>
                        <div class="panel-body markdown">
@@ -44,7 +44,7 @@
                    </div>
                 </div>
                 {{end}}
-                <div class="issue-child issue-closed">
+                <!-- <div class="issue-child issue-closed">
                     <a class="user pull-left" href="{user.link}"><img class="avatar" src="{user.avatar}" alt=""/></a>
                     <div class="issue-content">
                         <a class="user pull-left" href="{user.link}">{user.name}</a>
@@ -59,7 +59,7 @@
                         <span class="btn btn-success">Reopened</span> this
                         <span class="time">{close.time}</span>
                     </div>
-                </div>
+                </div> -->
                 <hr class="issue-line"/>
                 <div class="issue-child issue-reply">
                     <a class="user pull-left" href="/user/{{.SignedUser.Name}}"><img class="avatar" src="{{.SignedUser.AvatarLink}}" alt=""/></a>
@@ -86,9 +86,11 @@
                             </div>
                             <div class="text-right">
                                 <div class="form-group">
-                                    <input type="hidden" value="id" name="repo-id"/>
-                                    <button class="btn-default btn issue-open" id="issue-open-btn" data-origin="Re-Open" data-text="Re-Open & Comment">Open</button>&nbsp;&nbsp;
-                                    <button class="btn-default btn issue-close" id="issue-close-btn" data-origin="Close" data-text="Close & Comment">Close</button>&nbsp;&nbsp;
+                                    {{if .Issue.IsClosed}}
+                                    <input type="hidden" value="reopen" name="change_status"/>
+                                    <button class="btn-default btn issue-open" id="issue-open-btn" data-origin="Re-Open" data-text="Re-Open & Comment">Reopen</button>{{else}}
+                                    <input type="hidden" value="close" name="change_status"/>
+                                    <button class="btn-default btn issue-close" id="issue-close-btn" data-origin="Close" data-text="Close & Comment">Close</button>{{end}}&nbsp;&nbsp;
                                     <button class="btn-success btn" id="issue-reply-btn">Comment</button>
                                 </div>
                             </div>