From 0fd754bbe0dab966ad3070dc24f9583c67c84513 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 28 Mar 2014 07:26:22 -0400 Subject: [PATCH 01/10] Working on install page --- models/models.go | 4 +-- modules/base/conf.go | 4 +++ routers/install.go | 26 +++++++++++++++++--- serve.go | 2 +- templates/install.tmpl | 55 ++++++++++++++++++++---------------------- update.go | 2 +- 6 files changed, 56 insertions(+), 37 deletions(-) diff --git a/models/models.go b/models/models.go index 813725be4..04a361c59 100644 --- a/models/models.go +++ b/models/models.go @@ -34,7 +34,7 @@ func LoadModelsConfig() { DbCfg.Path = base.Cfg.MustValue("database", "PATH", "data/gogs.db") } -func setEngine() { +func SetEngine() { var err error switch DbCfg.Type { case "mysql": @@ -70,7 +70,7 @@ func setEngine() { } func NewEngine() { - setEngine() + SetEngine() if err := orm.Sync(new(User), new(PublicKey), new(Repository), new(Watch), new(Action), new(Access), new(Issue), new(Comment)); err != nil { fmt.Printf("sync database struct error: %v\n", err) diff --git a/modules/base/conf.go b/modules/base/conf.go index 2e5688393..f905c3814 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -38,6 +38,8 @@ var ( RunUser string RepoRootPath string + InstallLock bool + EnableHttpsClone bool LogInRememberDays int @@ -282,6 +284,8 @@ func NewConfigContext() { os.Exit(2) } + InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false) + EnableHttpsClone = Cfg.MustBool("security", "ENABLE_HTTPS_CLONE", false) LogInRememberDays = Cfg.MustInt("security", "LOGIN_REMEMBER_DAYS") diff --git a/routers/install.go b/routers/install.go index d7d5159ef..b44b89034 100644 --- a/routers/install.go +++ b/routers/install.go @@ -4,10 +4,28 @@ package routers -import "github.com/gogits/gogs/modules/middleware" +import ( + "errors" + + "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/middleware" +) + +func Install(ctx *middleware.Context) { + if base.InstallLock { + ctx.Handle(404, "install.Install", errors.New("Installation is prohibited")) + return + } -func Install(ctx *middleware.Context){ - ctx.Data["PageIsInstall"] = true ctx.Data["Title"] = "Install" - ctx.HTML(200,"install") + ctx.Data["DbCfg"] = models.DbCfg + ctx.Data["RepoRootPath"] = base.RepoRootPath + ctx.Data["RunUser"] = base.RunUser + ctx.Data["PageIsInstall"] = true + + if ctx.Req.Method == "GET" { + ctx.HTML(200, "install") + return + } } diff --git a/serve.go b/serve.go index 96f03e724..ad31260f0 100644 --- a/serve.go +++ b/serve.go @@ -78,7 +78,7 @@ func runServ(k *cli.Context) { base.NewConfigContext() models.LoadModelsConfig() - models.NewEngine() + models.SetEngine() keys := strings.Split(os.Args[2], "-") if len(keys) != 2 { diff --git a/templates/install.tmpl b/templates/install.tmpl index 4fbef3cba..99ac8421f 100644 --- a/templates/install.tmpl +++ b/templates/install.tmpl @@ -12,7 +12,7 @@ @@ -21,28 +21,21 @@
- -
- -
- - -
- +
- +
- +
@@ -50,7 +43,7 @@
- +

Recommend use INNODB engine with utf8_general_ci charset.

@@ -71,18 +64,12 @@
- -

The file path of SQLite database.

+ +

The file path of SQLite3 database.

- -

General Settings of Gogs

@@ -91,7 +78,7 @@
- +

The git copy of each repository is saved in this directory.

@@ -100,7 +87,7 @@
- +

The user has access to visit and run Gogs.

@@ -113,20 +100,30 @@
- +
+
- + +
+
+ +
+ + +
+

+
- +
- +

@@ -168,7 +165,7 @@
@@ -179,7 +176,7 @@
diff --git a/update.go b/update.go index 39729937e..23abd7b2e 100644 --- a/update.go +++ b/update.go @@ -32,7 +32,7 @@ gogs serv provide access auth for repositories`, func runUpdate(c *cli.Context) { base.NewConfigContext() models.LoadModelsConfig() - models.NewEngine() + models.SetEngine() w, _ := os.Create("update.log") defer w.Close() From d800a44a26216747b1a60a21090c581dfbe23ff4 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 28 Mar 2014 19:34:01 +0800 Subject: [PATCH 02/10] display commits by sha1 id --- models/git.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/git.go b/models/git.go index e2ee52083..34f0267f6 100644 --- a/models/git.go +++ b/models/git.go @@ -244,11 +244,11 @@ func GetCommitsByCommitId(userName, repoName, commitId string) (*list.List, erro if err != nil { return nil, err } - r, err := repo.LookupReference(commitId) + oid, err := git.NewOidFromString(commitId) if err != nil { return nil, err } - return r.AllCommits() + return repo.CommitsBefore(oid) } // Diff line types. From 6bd4f34c8dad50da5dc861ffdaebae1577f8881e Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 28 Mar 2014 19:36:01 +0800 Subject: [PATCH 03/10] fix commits button --- templates/repo/toolbar.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/repo/toolbar.tmpl b/templates/repo/toolbar.tmpl index ac516c37d..75f1efdc8 100644 --- a/templates/repo/toolbar.tmpl +++ b/templates/repo/toolbar.tmpl @@ -5,7 +5,7 @@
- \ No newline at end of file + From cb05b8325cdd85dda9bbebf61d8993da34d80e70 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 28 Mar 2014 08:39:35 -0400 Subject: [PATCH 04/10] Update config option --- conf/app.ini | 2 -- gogs.go | 2 +- modules/base/conf.go | 4 ---- modules/middleware/repo.go | 6 +----- routers/admin/admin.go | 1 - templates/admin/config.tmpl | 1 - templates/base/navbar.tmpl | 2 +- templates/home.tmpl | 4 +++- templates/install.tmpl | 2 +- 9 files changed, 7 insertions(+), 17 deletions(-) diff --git a/conf/app.ini b/conf/app.ini index d988b4acb..a3c749be0 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -33,8 +33,6 @@ PATH = data/gogs.db [security] INSTALL_LOCK = false -; Use HTTPS to clone repository, otherwise use HTTP. -ENABLE_HTTPS_CLONE = false ; !!CHANGE THIS TO KEEP YOUR USER DATA SAFE!! SECRET_KEY = !#@FDEWREWR&*( ; Auto-login remember days diff --git a/gogs.go b/gogs.go index f2f408ccc..f4b7c72fe 100644 --- a/gogs.go +++ b/gogs.go @@ -19,7 +19,7 @@ import ( // Test that go1.2 tag above is included in builds. main.go refers to this definition. const go12tag = true -const APP_VER = "0.1.9.0327 Alpha" +const APP_VER = "0.1.9.0328 Alpha" func init() { base.AppVer = APP_VER diff --git a/modules/base/conf.go b/modules/base/conf.go index f905c3814..b3a987e64 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -40,8 +40,6 @@ var ( InstallLock bool - EnableHttpsClone bool - LogInRememberDays int CookieUserName string CookieRememberName string @@ -286,8 +284,6 @@ func NewConfigContext() { InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false) - EnableHttpsClone = Cfg.MustBool("security", "ENABLE_HTTPS_CLONE", false) - LogInRememberDays = Cfg.MustInt("security", "LOGIN_REMEMBER_DAYS") CookieUserName = Cfg.MustValue("security", "COOKIE_USERNAME") CookieRememberName = Cfg.MustValue("security", "COOKIE_REMEMBER_NAME") diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index cb4a8632a..54b735af0 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -71,12 +71,8 @@ func RepoAssignment(redirect bool) martini.Handler { ctx.Repo.IsWatching = models.IsWatching(ctx.User.Id, repo.Id) } ctx.Repo.Repository = repo - scheme := "http" - if base.EnableHttpsClone { - scheme = "https" - } 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/%s.git", scheme, base.Domain, user.LowerName, repo.LowerName) + ctx.Repo.CloneLink.HTTPS = fmt.Sprintf("%s%s/%s.git", base.AppUrl, user.LowerName, repo.LowerName) if len(params["branchname"]) == 0 { params["branchname"] = "master" diff --git a/routers/admin/admin.go b/routers/admin/admin.go index 0b5e3d8e7..f303439fd 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -141,7 +141,6 @@ func Config(ctx *middleware.Context) { ctx.Data["Domain"] = base.Domain ctx.Data["RunUser"] = base.RunUser ctx.Data["RunMode"] = strings.Title(martini.Env) - ctx.Data["EnableHttpsClone"] = base.EnableHttpsClone ctx.Data["RepoRootPath"] = base.RepoRootPath ctx.Data["Service"] = base.Service diff --git a/templates/admin/config.tmpl b/templates/admin/config.tmpl index 39895aa31..ab805d8de 100644 --- a/templates/admin/config.tmpl +++ b/templates/admin/config.tmpl @@ -17,7 +17,6 @@
Run User: {{.RunUser}}
Run Mode: {{.RunMode}}

-
Enable HTTPS Clone
Repository Root Path: {{.RepoRootPath}}
diff --git a/templates/base/navbar.tmpl b/templates/base/navbar.tmpl index 829ecba62..7d1f64e49 100644 --- a/templates/base/navbar.tmpl +++ b/templates/base/navbar.tmpl @@ -3,7 +3,7 @@