From d01820c125669367b7a585d767d5f11e73a701c2 Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Sat, 29 Mar 2014 13:40:22 +0800 Subject: conf support mysql port --- models/models.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'models') diff --git a/models/models.go b/models/models.go index 04a361c5..bafa1747 100644 --- a/models/models.go +++ b/models/models.go @@ -38,7 +38,7 @@ func SetEngine() { var err error switch DbCfg.Type { case "mysql": - orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@%s/%s?charset=utf8", + orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", DbCfg.User, DbCfg.Pwd, DbCfg.Host, DbCfg.Name)) case "postgres": orm, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s", -- cgit v1.2.3 From 828282882066aa4e8bd8fb0c083c530607bc34bb Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 29 Mar 2014 07:50:25 -0400 Subject: Fix action email bug --- models/action.go | 13 +++++++++---- modules/base/tool.go | 8 +++++--- routers/repo/issue.go | 2 +- routers/user/user.go | 2 +- templates/user/dashboard.tmpl | 2 +- templates/user/profile.tmpl | 2 +- 6 files changed, 18 insertions(+), 11 deletions(-) (limited to 'models') diff --git a/models/action.go b/models/action.go index 9d99df85..89485578 100644 --- a/models/action.go +++ b/models/action.go @@ -31,6 +31,7 @@ type Action struct { OpType int // Operations: CREATE DELETE STAR ... ActUserId int64 // Action user id. ActUserName string // Action user name. + ActEmail string RepoId int64 RepoName string RefName string @@ -46,6 +47,10 @@ func (a Action) GetActUserName() string { return a.ActUserName } +func (a Action) GetActEmail() string { + return a.ActEmail +} + func (a Action) GetRepoName() string { return a.RepoName } @@ -69,8 +74,8 @@ func CommitRepoAction(userId int64, userName string, return err } - if err = NotifyWatchers(&Action{ActUserId: userId, ActUserName: userName, OpType: OP_COMMIT_REPO, - Content: string(bs), RepoId: repoId, RepoName: repoName, RefName: refName}); err != nil { + if err = NotifyWatchers(&Action{ActUserId: userId, ActUserName: userName, ActEmail: "", + OpType: OP_COMMIT_REPO, Content: string(bs), RepoId: repoId, RepoName: repoName, RefName: refName}); err != nil { log.Error("action.CommitRepoAction(notify watchers): %d/%s", userId, repoName) return err } @@ -93,8 +98,8 @@ func CommitRepoAction(userId int64, userName string, // NewRepoAction adds new action for creating repository. func NewRepoAction(user *User, repo *Repository) (err error) { - if err = NotifyWatchers(&Action{ActUserId: user.Id, ActUserName: user.Name, OpType: OP_CREATE_REPO, - RepoId: repo.Id, RepoName: repo.Name}); err != nil { + if err = NotifyWatchers(&Action{ActUserId: user.Id, ActUserName: user.Name, ActEmail: user.Email, + OpType: OP_CREATE_REPO, RepoId: repo.Id, RepoName: repo.Name}); err != nil { log.Error("action.NewRepoAction(notify watchers): %d/%s", user.Id, repo.Name) return err } diff --git a/modules/base/tool.go b/modules/base/tool.go index d005ffe3..6876da76 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -478,6 +478,7 @@ func (a argInt) Get(i int, args ...int) (r int) { type Actioner interface { GetOpType() int GetActUserName() string + GetActEmail() string GetRepoName() string GetBranch() string GetContent() string @@ -520,8 +521,9 @@ type PushCommits struct { // ActionDesc accepts int that represents action operation type // and returns the description. -func ActionDesc(act Actioner, avatarLink string) string { +func ActionDesc(act Actioner) string { actUserName := act.GetActUserName() + email := act.GetActEmail() repoName := act.GetRepoName() repoLink := actUserName + "/" + repoName branch := act.GetBranch() @@ -536,7 +538,7 @@ func ActionDesc(act Actioner, avatarLink string) string { } buf := bytes.NewBuffer([]byte("\n")) for _, commit := range push.Commits { - buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, avatarLink, repoLink, commit.Sha1, commit.Sha1[:7], commit.Message) + "\n") + buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, AvatarLink(commit.AuthorEmail), repoLink, commit.Sha1, commit.Sha1[:7], commit.Message) + "\n") } if push.Len > 3 { buf.WriteString(fmt.Sprintf(`
%d other commits >>
`, actUserName, repoName, branch, push.Len)) @@ -546,7 +548,7 @@ func ActionDesc(act Actioner, avatarLink string) string { case 6: // Create issue. infos := strings.SplitN(content, "|", 2) return fmt.Sprintf(TPL_CREATE_Issue, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0], - avatarLink, infos[1]) + AvatarLink(email), infos[1]) default: return "invalid type" } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 14876e18..c89c8b56 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -105,7 +105,7 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat } // Notify watchers. - if err = models.NotifyWatchers(&models.Action{ActUserId: ctx.User.Id, ActUserName: ctx.User.Name, + if err = models.NotifyWatchers(&models.Action{ActUserId: ctx.User.Id, ActUserName: ctx.User.Name, ActEmail: ctx.User.Email, OpType: models.OP_CREATE_ISSUE, Content: fmt.Sprintf("%d|%s", issue.Index, issue.Name), RepoId: ctx.Repo.Repository.Id, RepoName: ctx.Repo.Repository.Name, RefName: ""}); err != nil { ctx.Handle(200, "issue.CreateIssue", err) diff --git a/routers/user/user.go b/routers/user/user.go index b0fc5839..114169e6 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -279,7 +279,7 @@ func Feeds(ctx *middleware.Context, form auth.FeedsForm) { feeds := make([]string, len(actions)) for i := range actions { feeds[i] = fmt.Sprintf(TPL_FEED, base.ActionIcon(actions[i].OpType), - base.TimeSince(actions[i].Created), base.ActionDesc(actions[i], ctx.User.AvatarLink())) + base.TimeSince(actions[i].Created), base.ActionDesc(actions[i])) } ctx.JSON(200, &feeds) } diff --git a/templates/user/dashboard.tmpl b/templates/user/dashboard.tmpl index 6064095b..bc0853fb 100644 --- a/templates/user/dashboard.tmpl +++ b/templates/user/dashboard.tmpl @@ -18,7 +18,7 @@ {{range .Feeds}}
  • -
    {{TimeSince .Created}}
    {{ActionDesc . $.SignedUser.AvatarLink | str2html}}
    +
    {{TimeSince .Created}}
    {{ActionDesc . | str2html}}
  • {{else}} diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 5ac8121f..97549d48 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -35,7 +35,7 @@ {{range .Feeds}}
  • -
    {{TimeSince .Created}}
    {{ActionDesc . $.Owner.AvatarLink | str2html}}
    +
    {{TimeSince .Created}}
    {{ActionDesc . | str2html}}
  • {{else}} -- cgit v1.2.3 From ec1b801732b030648c060d26ce5a3ed8cf2e822c Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 29 Mar 2014 19:59:02 +0800 Subject: bug fixed --- models/action.go | 4 ++-- update.go | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'models') diff --git a/models/action.go b/models/action.go index 89485578..1e55df85 100644 --- a/models/action.go +++ b/models/action.go @@ -64,7 +64,7 @@ func (a Action) GetContent() string { } // CommitRepoAction adds new action for committing repository. -func CommitRepoAction(userId int64, userName string, +func CommitRepoAction(userId int64, userName, actEmail string, repoId int64, repoName string, refName string, commit *base.PushCommits) error { log.Trace("action.CommitRepoAction(start): %d/%s", userId, repoName) @@ -74,7 +74,7 @@ func CommitRepoAction(userId int64, userName string, return err } - if err = NotifyWatchers(&Action{ActUserId: userId, ActUserName: userName, ActEmail: "", + if err = NotifyWatchers(&Action{ActUserId: userId, ActUserName: userName, ActEmail: actEmail, OpType: OP_COMMIT_REPO, Content: string(bs), RepoId: repoId, RepoName: repoName, RefName: refName}); err != nil { log.Error("action.CommitRepoAction(notify watchers): %d/%s", userId, repoName) return err diff --git a/update.go b/update.go index 9743dcc4..246c5d8f 100644 --- a/update.go +++ b/update.go @@ -132,8 +132,12 @@ func runUpdate(c *cli.Context) { commits := make([]*base.PushCommit, 0) var maxCommits = 3 + var actEmail string for e := l.Front(); e != nil; e = e.Next() { commit := e.Value.(*git.Commit) + if actEmail == "" { + actEmail = commit.Committer.Email + } commits = append(commits, &base.PushCommit{commit.Id().String(), commit.Message(), @@ -145,7 +149,7 @@ func runUpdate(c *cli.Context) { } //commits = append(commits, []string{lastCommit.Id().String(), lastCommit.Message()}) - if err = models.CommitRepoAction(int64(sUserId), userName, + if err = models.CommitRepoAction(int64(sUserId), userName, actEmail, repos.Id, repoName, git.BranchName(refName), &base.PushCommits{l.Len(), commits}); err != nil { log.Error("runUpdate.models.CommitRepoAction: %v", err) } -- cgit v1.2.3 From 2c073afbec4b9845e8ddd10a4d3f469874fdcd37 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 29 Mar 2014 10:01:52 -0400 Subject: Mirror fix and update --- README.md | 2 ++ models/repo.go | 13 ++++++++++--- routers/api/v1/miscellaneous.go | 18 ++++++++++++++++++ routers/preview.go | 17 ----------------- templates/issue/create.tmpl | 4 ++-- templates/issue/view.tmpl | 4 ++-- templates/user/signin.tmpl | 2 +- web.go | 7 ++++++- 8 files changed, 41 insertions(+), 26 deletions(-) create mode 100644 routers/api/v1/miscellaneous.go delete mode 100644 routers/preview.go (limited to 'models') diff --git a/README.md b/README.md index 7d688506..e88a2477 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language ##### Current version: 0.1.9 Alpha +#### Due to testing purpose, data of [try.gogits.org](http://try.gogits.org) has been reset in March 29, 2014 and will reset multiple times after. Please do NOT put your important data on the site. + #### Other language version - [简体中文](README_ZH.md) diff --git a/models/repo.go b/models/repo.go index 4be655d2..a848694d 100644 --- a/models/repo.go +++ b/models/repo.go @@ -198,12 +198,19 @@ func CreateRepository(user *User, repoName, desc, repoLang, license string, priv c := exec.Command("git", "update-server-info") c.Dir = repoPath - err = c.Run() - if err != nil { + if err = c.Run(); err != nil { log.Error("repo.CreateRepository(exec update-server-info): %v", err) } - return repo, NewRepoAction(user, repo) + if err = NewRepoAction(user, repo); err != nil { + log.Error("repo.CreateRepository(NewRepoAction): %v", err) + } + + if err = WatchRepo(user.Id, repo.Id, true); err != nil { + log.Error("repo.CreateRepository(WatchRepo): %v", err) + } + + return repo, nil } // extractGitBareZip extracts git-bare.zip to repository path. diff --git a/routers/api/v1/miscellaneous.go b/routers/api/v1/miscellaneous.go new file mode 100644 index 00000000..0ff1eb04 --- /dev/null +++ b/routers/api/v1/miscellaneous.go @@ -0,0 +1,18 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package v1 + +import ( + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/middleware" +) + +func Markdown(ctx *middleware.Context) { + content := ctx.Query("content") + ctx.Render.JSON(200, map[string]interface{}{ + "ok": true, + "content": string(base.RenderMarkdown([]byte(content), "")), + }) +} diff --git a/routers/preview.go b/routers/preview.go deleted file mode 100644 index cc34c8fa..00000000 --- a/routers/preview.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package routers - -import "github.com/gogits/gogs/modules/middleware" - -func Preview(ctx *middleware.Context) { - content := ctx.Query("content") - // todo : gfm render content - // content = Markdown(content) - ctx.Render.JSON(200, map[string]interface{}{ - "ok": true, - "content": "preview : " + content, - }) -} diff --git a/templates/issue/create.tmpl b/templates/issue/create.tmpl index b8a533a1..f5cec0c0 100644 --- a/templates/issue/create.tmpl +++ b/templates/issue/create.tmpl @@ -15,11 +15,11 @@
    - Content with Markdown + Content with Markdown
    diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index 431b1d10..c357f535 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -69,11 +69,11 @@
    - Content with Markdown + Content with Markdown
    diff --git a/templates/user/signin.tmpl b/templates/user/signin.tmpl index 49a22626..b6c39af1 100644 --- a/templates/user/signin.tmpl +++ b/templates/user/signin.tmpl @@ -44,7 +44,7 @@
    diff --git a/web.go b/web.go index 451e52ff..7725791e 100644 --- a/web.go +++ b/web.go @@ -24,6 +24,7 @@ import ( "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/routers" "github.com/gogits/gogs/routers/admin" + "github.com/gogits/gogs/routers/api/v1" "github.com/gogits/gogs/routers/dev" "github.com/gogits/gogs/routers/repo" "github.com/gogits/gogs/routers/user" @@ -72,6 +73,7 @@ func newMartini() *martini.ClassicMartini { } func runWeb(*cli.Context) { + fmt.Println("Server is running...") globalInit() base.NewServices() checkRunMode() @@ -95,7 +97,10 @@ func runWeb(*cli.Context) { m.Get("/pulls", reqSignIn, user.Pulls) m.Get("/stars", reqSignIn, user.Stars) m.Get("/help", routers.Help) - m.Post("/preview", routers.Preview) + + m.Group("/api/v1", func(r martini.Router) { + r.Post("/markdown", v1.Markdown) + }) avt := avatar.CacheServer("public/img/avatar/", "public/img/avatar_default.jpg") m.Get("/avatar/:hash", avt.ServeHTTP) -- cgit v1.2.3 From ffa59739b609ce00ce21344531f27d4003dfc688 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 29 Mar 2014 10:24:42 -0400 Subject: Add edit issue --- models/issue.go | 35 ++++++++++++++++++----------------- routers/repo/issue.go | 10 +++++++--- templates/issue/view.tmpl | 14 +++++++------- 3 files changed, 32 insertions(+), 27 deletions(-) (limited to 'models') diff --git a/models/issue.go b/models/issue.go index 39558ae2..9fd1b905 100644 --- a/models/issue.go +++ b/models/issue.go @@ -18,23 +18,24 @@ var ( // Issue represents an issue or pull request of repository. type Issue struct { - Id int64 - Index int64 // Index in one repository. - Name string - RepoId int64 `xorm:"index"` - Repo *Repository `xorm:"-"` - PosterId int64 - Poster *User `xorm:"-"` - MilestoneId int64 - AssigneeId int64 - IsPull bool // Indicates whether is a pull request or not. - IsClosed bool - Labels string `xorm:"TEXT"` - Mentions string `xorm:"TEXT"` - Content string `xorm:"TEXT"` - NumComments int - Created time.Time `xorm:"created"` - Updated time.Time `xorm:"updated"` + Id int64 + Index int64 // Index in one repository. + Name string + RepoId int64 `xorm:"index"` + Repo *Repository `xorm:"-"` + PosterId int64 + Poster *User `xorm:"-"` + MilestoneId int64 + AssigneeId int64 + IsPull bool // Indicates whether is a pull request or not. + IsClosed bool + Labels string `xorm:"TEXT"` + Mentions string `xorm:"TEXT"` + Content string `xorm:"TEXT"` + RenderedContent string `xorm:"-"` + NumComments int + Created time.Time `xorm:"created"` + Updated time.Time `xorm:"updated"` } // CreateIssue creates new issue for repository. diff --git a/routers/repo/issue.go b/routers/repo/issue.go index c89c8b56..b38967f7 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -152,7 +152,7 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) { return } issue.Poster = u - issue.Content = string(base.RenderMarkdown([]byte(issue.Content), "")) + issue.RenderedContent = string(base.RenderMarkdown([]byte(issue.Content), "")) // Get comments. comments, err := models.GetIssueComments(issue.Id) @@ -216,8 +216,12 @@ func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat return } - ctx.Data["Title"] = issue.Name - ctx.Data["Issue"] = issue + ctx.JSON(200, map[string]interface{}{ + "ok": true, + "title": issue.Name, + "content": string(base.RenderMarkdown([]byte(issue.Content), "")), + "raw_content": issue.Content, + }) } func Comment(ctx *middleware.Context, params martini.Params) { diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index c357f535..c6f1444e 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -4,17 +4,17 @@ {{template "repo/toolbar" .}}
    -
    +
    #{{.Issue.Index}}

    {{.Issue.Name}}

    - - + +

    Edit - + {{if .Issue.IsClosed}}Closed{{else}}Open{{end}} {{.Issue.Poster.Name}} opened this issue {{TimeSince .Issue.Created}} · {{.Issue.NumComments}} comments @@ -24,13 +24,13 @@

    - {{str2html .Issue.Content}} + {{str2html .Issue.RenderedContent}}
    - +
    {{range .Comments}} -
    +
    -- cgit v1.2.3 From 107a1eadac72e610a9bcb68498751ca51ec8f51a Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 29 Mar 2014 17:50:51 -0400 Subject: Finish close and reopen issue, install page, ready going to test stage of v0.2.0 --- README.md | 2 +- README_ZH.md | 2 +- gogs.go | 2 +- models/issue.go | 36 ++++++++++-- models/models.go | 24 ++++---- models/repo.go | 25 ++++---- modules/auth/auth.go | 1 + modules/base/conf.go | 7 ++- public/css/gogs.css | 6 +- routers/install.go | 141 ++++++++++++++++++++++++++++++++++++++++++++-- routers/repo/issue.go | 62 +++++++++++++------- routers/user/user.go | 14 ++--- templates/install.tmpl | 59 ++++++++++--------- templates/issue/view.tmpl | 65 +++++++++++---------- web.go | 28 +-------- 15 files changed, 314 insertions(+), 160 deletions(-) (limited to 'models') diff --git a/README.md b/README.md index e88a2477..1d3aaf3e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language ![Demo](http://gowalker.org/public/gogs_demo.gif) -##### Current version: 0.1.9 Alpha +##### Current version: 0.2.0 Alpha #### Due to testing purpose, data of [try.gogits.org](http://try.gogits.org) has been reset in March 29, 2014 and will reset multiple times after. Please do NOT put your important data on the site. diff --git a/README_ZH.md b/README_ZH.md index 8e187c73..4590e36b 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个由 Go 语言编写的自助 Git 托管服务。 ![Demo](http://gowalker.org/public/gogs_demo.gif) -##### 当前版本:0.1.9 Alpha +##### 当前版本:0.2.0 Alpha ## 开发目的 diff --git a/gogs.go b/gogs.go index f1372f0c..2ef35ca4 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.0329 Alpha" +const APP_VER = "0.2.0.0329 Alpha" func init() { base.AppVer = APP_VER diff --git a/models/issue.go b/models/issue.go index 9fd1b905..f14030df 100644 --- a/models/issue.go +++ b/models/issue.go @@ -170,9 +170,17 @@ type Milestone struct { Created time.Time `xorm:"created"` } +// Issue types. +const ( + IT_PLAIN = iota // Pure comment. + IT_REOPEN // Issue reopen status change prompt. + IT_CLOSE // Issue close status change prompt. +) + // Comment represents a comment in commit and issue page. type Comment struct { Id int64 + Type int PosterId int64 Poster *User `xorm:"-"` IssueId int64 @@ -183,21 +191,37 @@ type Comment struct { } // CreateComment creates comment of issue or commit. -func CreateComment(userId, issueId, commitId, line int64, content string) error { +func CreateComment(userId, repoId, issueId, commitId, line int64, cmtType int, content string) error { sess := orm.NewSession() defer sess.Close() sess.Begin() - if _, err := orm.Insert(&Comment{PosterId: userId, IssueId: issueId, + if _, err := orm.Insert(&Comment{PosterId: userId, Type: cmtType, IssueId: issueId, CommitId: commitId, Line: line, Content: content}); err != nil { sess.Rollback() return err } - rawSql := "UPDATE `issue` SET num_comments = num_comments + 1 WHERE id = ?" - if _, err := sess.Exec(rawSql, issueId); err != nil { - sess.Rollback() - return err + // Check comment type. + switch cmtType { + case IT_PLAIN: + rawSql := "UPDATE `issue` SET num_comments = num_comments + 1 WHERE id = ?" + if _, err := sess.Exec(rawSql, issueId); err != nil { + sess.Rollback() + return err + } + case IT_REOPEN: + rawSql := "UPDATE `repository` SET num_closed_issues = num_closed_issues - 1 WHERE id = ?" + if _, err := sess.Exec(rawSql, repoId); err != nil { + sess.Rollback() + return err + } + case IT_CLOSE: + rawSql := "UPDATE `repository` SET num_closed_issues = num_closed_issues + 1 WHERE id = ?" + if _, err := sess.Exec(rawSql, repoId); err != nil { + sess.Rollback() + return err + } } return sess.Commit() } diff --git a/models/models.go b/models/models.go index bafa1747..825730c5 100644 --- a/models/models.go +++ b/models/models.go @@ -34,8 +34,7 @@ func LoadModelsConfig() { DbCfg.Path = base.Cfg.MustValue("database", "PATH", "data/gogs.db") } -func SetEngine() { - var err error +func SetEngine() (err error) { switch DbCfg.Type { case "mysql": orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", @@ -47,12 +46,10 @@ func SetEngine() { os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm) orm, err = xorm.NewEngine("sqlite3", DbCfg.Path) default: - fmt.Printf("Unknown database type: %s\n", DbCfg.Type) - os.Exit(2) + return fmt.Errorf("Unknown database type: %s\n", DbCfg.Type) } if err != nil { - fmt.Printf("models.init(fail to conntect database): %v\n", err) - os.Exit(2) + return fmt.Errorf("models.init(fail to conntect database): %v\n", err) } // WARNNING: for serv command, MUST remove the output to os.stdout, @@ -62,20 +59,21 @@ func SetEngine() { //orm.ShowErr = true f, err := os.Create("xorm.log") if err != nil { - fmt.Printf("models.init(fail to create xorm.log): %v\n", err) - os.Exit(2) + return fmt.Errorf("models.init(fail to create xorm.log): %v\n", err) } orm.Logger = f orm.ShowSQL = true + return nil } -func NewEngine() { - SetEngine() - if err := orm.Sync(new(User), new(PublicKey), new(Repository), new(Watch), +func NewEngine() (err error) { + if err = SetEngine(); err != nil { + return err + } else 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) - os.Exit(2) + return fmt.Errorf("sync database struct error: %v\n", err) } + return nil } type Statistic struct { diff --git a/models/repo.go b/models/repo.go index a848694d..0b2bbe48 100644 --- a/models/repo.go +++ b/models/repo.go @@ -11,7 +11,6 @@ import ( "os" "os/exec" "path/filepath" - "regexp" "strings" "time" "unicode/utf8" @@ -59,15 +58,6 @@ func NewRepoContext() { os.Exit(2) } } - - // Initialize illegal patterns. - for i := range illegalPatterns[1:] { - pattern := "" - for j := range illegalPatterns[i+1] { - pattern += "[" + string(illegalPatterns[i+1][j]-32) + string(illegalPatterns[i+1][j]) + "]" - } - illegalPatterns[i+1] = pattern - } } // Repository represents a git repository. @@ -105,15 +95,20 @@ func IsRepositoryExist(user *User, repoName string) (bool, error) { } var ( - // Define as all lower case!! - illegalPatterns = []string{"[.][Gg][Ii][Tt]", "raw", "user", "help", "stars", "issues", "pulls", "commits", "repo", "template", "admin"} + illegalEquals = []string{"raw", "install", "api", "avatar", "user", "help", "stars", "issues", "pulls", "commits", "repo", "template", "admin"} + illegalSuffixs = []string{".git"} ) // IsLegalName returns false if name contains illegal characters. func IsLegalName(repoName string) bool { - for _, pattern := range illegalPatterns { - has, _ := regexp.MatchString(pattern, repoName) - if has { + repoName = strings.ToLower(repoName) + for _, char := range illegalEquals { + if repoName == char { + return false + } + } + for _, char := range illegalSuffixs { + if strings.HasSuffix(repoName, char) { return false } } diff --git a/modules/auth/auth.go b/modules/auth/auth.go index ac03a8f1..361f55b2 100644 --- a/modules/auth/auth.go +++ b/modules/auth/auth.go @@ -172,6 +172,7 @@ type InstallForm struct { DatabasePath string `form:"database_path"` RepoRootPath string `form:"repo_path"` RunUser string `form:"run_user"` + Domain string `form:"domain"` AppUrl string `form:"app_url"` AdminName string `form:"admin_name" binding:"Required"` AdminPasswd string `form:"admin_pwd" binding:"Required;MinSize(6);MaxSize(30)"` diff --git a/modules/base/conf.go b/modules/base/conf.go index fd77cfd3..f696d083 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -272,18 +272,19 @@ func NewConfigContext() { Domain = Cfg.MustValue("server", "DOMAIN") SecretKey = Cfg.MustValue("security", "SECRET_KEY") + InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false) + RunUser = Cfg.MustValue("", "RUN_USER") curUser := os.Getenv("USERNAME") if len(curUser) == 0 { curUser = os.Getenv("USER") } - if RunUser != curUser { + // Does not check run user when the install lock is off. + if InstallLock && RunUser != curUser { fmt.Printf("Expect user(%s) but current user is: %s\n", RunUser, curUser) os.Exit(2) } - InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false) - LogInRememberDays = Cfg.MustInt("security", "LOGIN_REMEMBER_DAYS") CookieUserName = Cfg.MustValue("security", "COOKIE_USERNAME") CookieRememberName = Cfg.MustValue("security", "COOKIE_REMEMBER_NAME") diff --git a/public/css/gogs.css b/public/css/gogs.css index d6c117c8..965c9096 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -1197,13 +1197,13 @@ html, body { line-height: 42px; } -#issue .issue-closed{ - border-bottom: 3px solid #CCC; +#issue .issue-closed, #issue .issue-opened { + border-bottom: 2px solid #CCC; margin-bottom: 24px; padding-bottom: 24px; } -#issue .issue-closed .btn-danger,#issue .issue-opened .btn-success{ +#issue .issue-closed .label-danger,#issue .issue-opened .label-success{ margin: 0 .8em; } diff --git a/routers/install.go b/routers/install.go index b5c3a936..407705b7 100644 --- a/routers/install.go +++ b/routers/install.go @@ -6,13 +6,46 @@ package routers import ( "errors" + "os" + "strings" + + "github.com/Unknwon/goconfig" + "github.com/codegangsta/martini" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/log" + "github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/middleware" ) +// Check run mode(Default of martini is Dev). +func checkRunMode() { + switch base.Cfg.MustValue("", "RUN_MODE") { + case "prod": + martini.Env = martini.Prod + case "test": + martini.Env = martini.Test + } + log.Info("Run Mode: %s", strings.Title(martini.Env)) +} + +// GlobalInit is for global configuration reload-able. +func GlobalInit() { + base.NewConfigContext() + mailer.NewMailerContext() + models.LoadModelsConfig() + models.LoadRepoConfig() + models.NewRepoContext() + if err := models.NewEngine(); err != nil && base.InstallLock { + log.Error("%v", err) + os.Exit(2) + } + base.NewServices() + checkRunMode() +} + func Install(ctx *middleware.Context, form auth.InstallForm) { if base.InstallLock { ctx.Handle(404, "install.Install", errors.New("Installation is prohibited")) @@ -20,14 +53,114 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { } ctx.Data["Title"] = "Install" - ctx.Data["DbCfg"] = models.DbCfg - ctx.Data["RepoRootPath"] = base.RepoRootPath - ctx.Data["RunUser"] = base.RunUser - ctx.Data["AppUrl"] = base.AppUrl ctx.Data["PageIsInstall"] = true + // Get and assign value to install form. + if len(form.Host) == 0 { + form.Host = models.DbCfg.Host + } + if len(form.User) == 0 { + form.User = models.DbCfg.User + } + if len(form.Passwd) == 0 { + form.Passwd = models.DbCfg.Pwd + } + if len(form.DatabaseName) == 0 { + form.DatabaseName = models.DbCfg.Name + } + if len(form.DatabasePath) == 0 { + form.DatabasePath = models.DbCfg.Path + } + + if len(form.RepoRootPath) == 0 { + form.RepoRootPath = base.RepoRootPath + } + if len(form.RunUser) == 0 { + form.RunUser = base.RunUser + } + if len(form.Domain) == 0 { + form.Domain = base.Domain + } + if len(form.AppUrl) == 0 { + form.AppUrl = base.AppUrl + } + + auth.AssignForm(form, ctx.Data) + if ctx.Req.Method == "GET" { ctx.HTML(200, "install") return } + + if ctx.HasError() { + ctx.HTML(200, "install") + return + } + + // Pass basic check, now test configuration. + // Test database setting. + dbTypes := map[string]string{"mysql": "mysql", "pgsql": "postgres", "sqlite": "sqlite3"} + models.DbCfg.Type = dbTypes[form.Database] + models.DbCfg.Host = form.Host + models.DbCfg.User = form.User + models.DbCfg.Pwd = form.Passwd + models.DbCfg.Name = form.DatabaseName + models.DbCfg.SslMode = form.SslMode + models.DbCfg.Path = form.DatabasePath + + if err := models.NewEngine(); err != nil { + ctx.RenderWithErr("Database setting is not correct: "+err.Error(), "install", &form) + return + } + + // Test repository root path. + if err := os.MkdirAll(form.RepoRootPath, os.ModePerm); err != nil { + ctx.RenderWithErr("Repository root path is invalid: "+err.Error(), "install", &form) + return + } + + // Create admin account. + if _, err := models.RegisterUser(&models.User{Name: form.AdminName, Email: form.AdminEmail, Passwd: form.AdminPasswd, + IsAdmin: true, IsActive: true}); err != nil { + if err != models.ErrUserAlreadyExist { + ctx.RenderWithErr("Admin account setting is invalid: "+err.Error(), "install", &form) + return + } + } + + // Save settings. + base.Cfg.SetValue("database", "DB_TYPE", models.DbCfg.Type) + base.Cfg.SetValue("database", "HOST", models.DbCfg.Host) + base.Cfg.SetValue("database", "NAME", models.DbCfg.Name) + base.Cfg.SetValue("database", "USER", models.DbCfg.User) + base.Cfg.SetValue("database", "PASSWD", models.DbCfg.Pwd) + base.Cfg.SetValue("database", "SSL_MODE", models.DbCfg.SslMode) + base.Cfg.SetValue("database", "PATH", models.DbCfg.Path) + + base.Cfg.SetValue("repository", "ROOT", form.RepoRootPath) + base.Cfg.SetValue("", "RUN_USER", form.RunUser) + base.Cfg.SetValue("server", "DOMAIN", form.Domain) + base.Cfg.SetValue("server", "ROOT_URL", form.AppUrl) + + if len(form.Host) > 0 { + base.Cfg.SetValue("mailer", "ENABLED", "true") + base.Cfg.SetValue("mailer", "HOST", form.SmtpHost) + base.Cfg.SetValue("mailer", "USER", form.SmtpEmail) + base.Cfg.SetValue("mailer", "PASSWD", form.SmtpPasswd) + + base.Cfg.SetValue("service", "REGISTER_EMAIL_CONFIRM", base.ToStr(form.RegisterConfirm == "on")) + base.Cfg.SetValue("service", "ENABLE_NOTIFY_MAIL", base.ToStr(form.MailNotify == "on")) + } + + base.Cfg.SetValue("security", "INSTALL_LOCK", "true") + + if err := goconfig.SaveConfigFile(base.Cfg, "custom/conf/app.ini"); err != nil { + ctx.RenderWithErr("Fail to save configuration: "+err.Error(), "install", &form) + return + } + + GlobalInit() + + log.Info("First-time run install finished!") + ctx.Redirect("/user/login") } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 337bd4bf..3506e901 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -7,6 +7,7 @@ package repo import ( "fmt" "net/url" + "strings" "github.com/codegangsta/martini" @@ -175,7 +176,7 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = issue.Name ctx.Data["Issue"] = issue ctx.Data["Comments"] = comments - ctx.Data["IsIssueOwner"] = issue.PosterId == ctx.User.Id + ctx.Data["IsIssueOwner"] = ctx.Repo.IsOwner || issue.PosterId == ctx.User.Id ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = false ctx.HTML(200, "issue/view") @@ -225,24 +226,17 @@ func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat } func Comment(ctx *middleware.Context, params martini.Params) { - fmt.Println(ctx.Query("change_status")) if !ctx.Repo.IsValid { ctx.Handle(404, "issue.Comment(invalid repo):", nil) } - index, err := base.StrTo(ctx.Query("issueIndex")).Int() + index, err := base.StrTo(ctx.Query("issueIndex")).Int64() if err != nil { - ctx.Handle(404, "issue.Comment", err) + ctx.Handle(404, "issue.Comment(get index)", err) 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)) + issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, index) if err != nil { if err == models.ErrIssueNotExist { ctx.Handle(404, "issue.Comment", err) @@ -252,16 +246,46 @@ func Comment(ctx *middleware.Context, params martini.Params) { return } - switch params["action"] { - case "new": - if err = models.CreateComment(ctx.User.Id, issue.Id, 0, 0, content); err != nil { - ctx.Handle(500, "issue.Comment(create comment)", err) + // Check if issue owner changes the status of issue. + var newStatus string + if ctx.Repo.IsOwner || issue.PosterId == ctx.User.Id { + newStatus = ctx.Query("change_status") + } + if len(newStatus) > 0 { + if (strings.Contains(newStatus, "Reopen") && issue.IsClosed) || + (strings.Contains(newStatus, "Close") && !issue.IsClosed) { + issue.IsClosed = !issue.IsClosed + if err = models.UpdateIssue(issue); err != nil { + ctx.Handle(200, "issue.Comment(update issue status)", err) + return + } + + cmtType := models.IT_CLOSE + if !issue.IsClosed { + cmtType = models.IT_REOPEN + } + + if err = models.CreateComment(ctx.User.Id, ctx.Repo.Repository.Id, issue.Id, 0, 0, cmtType, ""); err != nil { + ctx.Handle(200, "issue.Comment(create status change comment)", err) + return + } + log.Trace("%s Issue(%d) status changed: %v", ctx.Req.RequestURI, issue.Id, !issue.IsClosed) + } + } + + content := ctx.Query("content") + if len(content) > 0 { + switch params["action"] { + case "new": + if err = models.CreateComment(ctx.User.Id, ctx.Repo.Repository.Id, issue.Id, 0, 0, models.IT_PLAIN, content); err != nil { + ctx.Handle(500, "issue.Comment(create comment)", err) + return + } + log.Trace("%s Comment created: %d", ctx.Req.RequestURI, issue.Id) + default: + ctx.Handle(404, "issue.Comment", err) return } - log.Trace("%s Comment created: %d", ctx.Req.RequestURI, issue.Id) - default: - ctx.Handle(404, "issue.Comment", err) - return } ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", ctx.User.Name, ctx.Repo.Repository.Name, index)) diff --git a/routers/user/user.go b/routers/user/user.go index 114169e6..aeaf91c9 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -120,7 +120,7 @@ func SignIn(ctx *middleware.Context, form auth.LogInForm) { return } - if hasErr, ok := ctx.Data["HasError"]; ok && hasErr.(bool) { + if ctx.HasError() { ctx.HTML(200, "user/signin") return } @@ -308,17 +308,19 @@ func Issues(ctx *middleware.Context) { showRepos := make([]models.Repository, 0, len(repos)) - var closedIssueCount, createdByCount int + isShowClosed := ctx.Query("state") == "closed" + var closedIssueCount, createdByCount, allIssueCount int // Get all issues. allIssues := make([]models.Issue, 0, 5*len(repos)) for i, repo := range repos { - issues, err := models.GetIssues(0, repo.Id, posterId, 0, page, false, false, "", "") + issues, err := models.GetIssues(0, repo.Id, posterId, 0, page, isShowClosed, false, "", "") if err != nil { ctx.Handle(200, "user.Issues(get issues)", err) return } + allIssueCount += repo.NumIssues closedIssueCount += repo.NumClosedIssues // Set repository information to issues. @@ -330,12 +332,10 @@ func Issues(ctx *middleware.Context) { repos[i].NumOpenIssues = repo.NumIssues - repo.NumClosedIssues if repos[i].NumOpenIssues > 0 { showRepos = append(showRepos, repos[i]) - } } showIssues := make([]models.Issue, 0, len(allIssues)) - isShowClosed := ctx.Query("state") == "closed" ctx.Data["IsShowClosed"] = isShowClosed // Get posters and filter issues. @@ -361,9 +361,9 @@ func Issues(ctx *middleware.Context) { ctx.Data["Repos"] = showRepos ctx.Data["Issues"] = showIssues - ctx.Data["AllIssueCount"] = len(allIssues) + ctx.Data["AllIssueCount"] = allIssueCount ctx.Data["ClosedIssueCount"] = closedIssueCount - ctx.Data["OpenIssueCount"] = len(allIssues) - closedIssueCount + ctx.Data["OpenIssueCount"] = allIssueCount - closedIssueCount ctx.Data["CreatedByCount"] = createdByCount ctx.HTML(200, "issue/user") } diff --git a/templates/install.tmpl b/templates/install.tmpl index a456ac5f..20bd502d 100644 --- a/templates/install.tmpl +++ b/templates/install.tmpl @@ -3,9 +3,8 @@
    {{.CsrfTokenHtml}}

    Install Steps For First-time Run

    -
    {{.ErrorMsg}}
    -

    Gogs requires MySQL or PostgreSQL based on your choice

    +

    Gogs requires MySQL or PostgreSQL, SQLite3 only available for official binary version

    @@ -16,26 +15,28 @@
    +
    -
    - +
    +
    - +
    +
    - +
    @@ -43,7 +44,7 @@
    - +

    Recommend use INNODB engine with utf8_general_ci charset.

    @@ -59,12 +60,13 @@
    +
    - +

    The file path of SQLite3 database.

    @@ -73,12 +75,11 @@

    General Settings of Gogs

    -
    - +

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

    @@ -88,16 +89,25 @@
    - +

    The user has access to visit and run Gogs.

    +
    + + +
    + +

    This affects SSH clone URL.

    +
    +
    +
    - +

    This affects HTTP/HTTPS clone URL and somewhere in e-mail.

    @@ -105,35 +115,30 @@

    Admin Account Settings

    -
    -
    - +
    -
    +
    -
    - +
    -
    +
    -
    - +

    -
    - +
    - +

    @@ -175,7 +180,7 @@
    @@ -186,7 +191,7 @@
    diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index 0481a33b..91e5250c 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -30,37 +30,37 @@
    {{range .Comments}} -
    - -
    -
    - {{.Poster.Name}} commented {{TimeSince .Created}} - - Owner -
    -
    - {{str2html .Content}} -
    -
    -
    - {{end}} - + Owner +
    +
    + {{str2html .Content}} +
    +
    +
    + {{else if eq .Type 1}} +
    + +
    + {{.Poster.Name}} Reopened this issue {{TimeSince .Created}} +
    +
    + {{else if eq .Type 2}} +
    +
    - {user.name} - Closed this - {close.time} + {{.Poster.Name}} Closed this issue {{TimeSince .Created}}
    -
    -
    - -
    - {user.name} - Reopened this - {close.time} -
    -
    --> +
    + {{end}} + {{end}}
    {{if .SignedUser}}
    @@ -68,8 +68,7 @@ {{.CsrfTokenHtml}}
    -
    - Content with Markdown +
    Content with Markdown
    -
    loading...
    +
    Loading...
    {{if .Issue.IsClosed}} - {{else}} + {{else}} {{end}}  
    diff --git a/web.go b/web.go index 7098717a..6aabc0e9 100644 --- a/web.go +++ b/web.go @@ -8,19 +8,16 @@ import ( "fmt" "html/template" "net/http" - "strings" "github.com/codegangsta/cli" "github.com/codegangsta/martini" "github.com/gogits/binding" - "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/avatar" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" - "github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/routers" "github.com/gogits/gogs/routers/admin" @@ -40,27 +37,6 @@ and it takes care of all the other things for you`, Flags: []cli.Flag{}, } -// globalInit is for global configuration reload-able. -func globalInit() { - base.NewConfigContext() - mailer.NewMailerContext() - models.LoadModelsConfig() - models.LoadRepoConfig() - models.NewRepoContext() - models.NewEngine() -} - -// Check run mode(Default of martini is Dev). -func checkRunMode() { - switch base.Cfg.MustValue("", "RUN_MODE") { - case "prod": - martini.Env = martini.Prod - case "test": - martini.Env = martini.Test - } - log.Info("Run Mode: %s", strings.Title(martini.Env)) -} - func newMartini() *martini.ClassicMartini { r := martini.NewRouter() m := martini.New() @@ -74,9 +50,7 @@ func newMartini() *martini.ClassicMartini { func runWeb(*cli.Context) { fmt.Println("Server is running...") - globalInit() - base.NewServices() - checkRunMode() + routers.GlobalInit() log.Info("%s %s", base.AppName, base.AppVer) m := newMartini() -- cgit v1.2.3 From b27c34f39acee3bf7b6594a1f0db2183b343326c Mon Sep 17 00:00:00 2001 From: slene Date: Sun, 30 Mar 2014 10:13:02 +0800 Subject: update git api. fix link... and so on --- models/git.go | 26 ++++++++++++++++------- models/repo.go | 2 +- routers/repo/branch.go | 10 ++------- routers/repo/commit.go | 18 ++++++---------- routers/repo/repo.go | 51 +++++++++++---------------------------------- templates/issue/create.tmpl | 4 ++-- templates/issue/list.tmpl | 12 +++++------ templates/issue/view.tmpl | 4 ++-- templates/repo/diff.tmpl | 3 +-- templates/repo/single.tmpl | 4 ++-- templates/repo/toolbar.tmpl | 20 +++++++++--------- 11 files changed, 63 insertions(+), 91 deletions(-) (limited to 'models') diff --git a/models/git.go b/models/git.go index 34f0267f..d3bad6e0 100644 --- a/models/git.go +++ b/models/git.go @@ -70,9 +70,12 @@ func GetTargetFile(userName, repoName, branchName, commitId, rpath string) (*Rep return nil, err } - commit, err := repo.GetCommit(branchName, commitId) + commit, err := repo.GetCommitOfBranch(branchName) if err != nil { - return nil, err + commit, err = repo.GetCommit(commitId) + if err != nil { + return nil, err + } } parts := strings.Split(path.Clean(rpath), "/") @@ -110,13 +113,22 @@ func GetTargetFile(userName, repoName, branchName, commitId, rpath string) (*Rep } // GetReposFiles returns a list of file object in given directory of repository. -func GetReposFiles(userName, repoName, branchName, commitId, rpath string) ([]*RepoFile, error) { +// func GetReposFilesOfBranch(userName, repoName, branchName, rpath string) ([]*RepoFile, error) { +// return getReposFiles(userName, repoName, commitId, rpath) +// } + +// GetReposFiles returns a list of file object in given directory of repository. +func GetReposFiles(userName, repoName, commitId, rpath string) ([]*RepoFile, error) { + return getReposFiles(userName, repoName, commitId, rpath) +} + +func getReposFiles(userName, repoName, commitId string, rpath string) ([]*RepoFile, error) { repo, err := git.OpenRepository(RepoPath(userName, repoName)) if err != nil { return nil, err } - commit, err := repo.GetCommit(branchName, commitId) + commit, err := repo.GetCommit(commitId) if err != nil { return nil, err } @@ -216,13 +228,13 @@ func GetReposFiles(userName, repoName, branchName, commitId, rpath string) ([]*R return append(repodirs, repofiles...), nil } -func GetCommit(userName, repoName, branchname, commitid string) (*git.Commit, error) { +func GetCommit(userName, repoName, commitId string) (*git.Commit, error) { repo, err := git.OpenRepository(RepoPath(userName, repoName)) if err != nil { return nil, err } - return repo.GetCommit(branchname, commitid) + return repo.GetCommit(commitId) } // GetCommitsByBranch returns all commits of given branch of repository. @@ -397,7 +409,7 @@ func GetDiff(repoPath, commitid string) (*Diff, error) { return nil, err } - commit, err := repo.GetCommit("", commitid) + commit, err := repo.GetCommit(commitid) if err != nil { return nil, err } diff --git a/models/repo.go b/models/repo.go index 0b2bbe48..41105483 100644 --- a/models/repo.go +++ b/models/repo.go @@ -364,7 +364,7 @@ func GetRepos(num, offset int) ([]UserRepo, error) { } func RepoPath(userName, repoName string) string { - return filepath.Join(UserPath(userName), repoName+".git") + return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git") } func UpdateRepository(repo *Repository) error { diff --git a/routers/repo/branch.go b/routers/repo/branch.go index aed77cfa..c598db43 100644 --- a/routers/repo/branch.go +++ b/routers/repo/branch.go @@ -11,21 +11,15 @@ import ( ) func Branches(ctx *middleware.Context, params martini.Params) { - if !ctx.Repo.IsValid { - return - } - - brs, err := models.GetBranches(params["username"], params["reponame"]) + brs, err := models.GetBranches(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) if err != nil { - ctx.Handle(200, "repo.Branches", err) + ctx.Handle(404, "repo.Branches", err) return } else if len(brs) == 0 { ctx.Handle(404, "repo.Branches", nil) return } - ctx.Data["Username"] = params["username"] - ctx.Data["Reponame"] = params["reponame"] ctx.Data["Branches"] = brs ctx.Data["IsRepoToolbarBranches"] = true diff --git a/routers/repo/commit.go b/routers/repo/commit.go index afc1ffda..449f6443 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -50,16 +50,12 @@ func Commits(ctx *middleware.Context, params martini.Params) { } func Diff(ctx *middleware.Context, params martini.Params) { - userName := params["username"] - repoName := params["reponame"] - branchName := params["branchname"] - commitId := params["commitid"] + userName := ctx.Repo.Owner.Name + repoName := ctx.Repo.Repository.Name + branchName := ctx.Repo.BranchName + commitId := ctx.Repo.CommitId - commit, err := models.GetCommit(userName, repoName, branchName, commitId) - if err != nil { - ctx.Handle(404, "repo.Diff", err) - return - } + commit := ctx.Repo.Commit diff, err := models.GetDiff(models.RepoPath(userName, repoName), commitId) if err != nil { @@ -85,11 +81,9 @@ func Diff(ctx *middleware.Context, params martini.Params) { return isImage } - shortSha := params["commitid"][:10] ctx.Data["IsImageFile"] = isImageFile - ctx.Data["Title"] = commit.Message() + " · " + shortSha + ctx.Data["Title"] = commit.Message() + " · " + base.ShortSha(commitId) ctx.Data["Commit"] = commit - ctx.Data["ShortSha"] = shortSha ctx.Data["Diff"] = diff ctx.Data["IsRepoToolbarCommits"] = true ctx.Data["SourcePath"] = "/" + path.Join(userName, repoName, "src", commitId) diff --git a/routers/repo/repo.go b/routers/repo/repo.go index b9ac1f1c..c9c9af1e 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -53,20 +53,20 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) { } func Single(ctx *middleware.Context, params martini.Params) { - if !ctx.Repo.IsValid { - return - } + branchName := ctx.Repo.BranchName + commitId := ctx.Repo.CommitId + userName := ctx.Repo.Owner.Name + repoName := ctx.Repo.Repository.Name - branchName := params["branchname"] - userName := params["username"] - repoName := params["reponame"] + repoLink := ctx.Repo.RepoLink + branchLink := ctx.Repo.RepoLink + "/src/" + branchName + rawLink := ctx.Repo.RepoLink + "/raw/" + branchName // Get tree path treename := params["_1"] if len(treename) > 0 && treename[len(treename)-1] == '/' { - ctx.Redirect("/" + ctx.Repo.Owner.LowerName + "/" + - ctx.Repo.Repository.Name + "/src/" + branchName + "/" + treename[:len(treename)-1]) + ctx.Redirect(repoLink + "/src/" + branchName + "/" + treename[:len(treename)-1]) return } @@ -84,23 +84,17 @@ func Single(ctx *middleware.Context, params martini.Params) { } ctx.Data["Branches"] = brs - var commitId string - isViewBranch := models.IsBranchExist(userName, repoName, branchName) - if !isViewBranch { - commitId = branchName - } + isViewBranch := ctx.Repo.IsBranch ctx.Data["IsViewBranch"] = isViewBranch repoFile, err := models.GetTargetFile(userName, repoName, branchName, commitId, treename) + if err != nil && err != models.ErrRepoFileNotExist { ctx.Handle(404, "repo.Single(GetTargetFile)", err) return } - branchLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/src/" + branchName - rawLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/raw/" + branchName - if len(treename) != 0 && repoFile == nil { ctx.Handle(404, "repo.Single", nil) return @@ -142,8 +136,7 @@ func Single(ctx *middleware.Context, params martini.Params) { } else { // Directory and file list. - files, err := models.GetReposFiles(userName, repoName, - branchName, commitId, treename) + files, err := models.GetReposFiles(userName, repoName, ctx.Repo.CommitId, treename) if err != nil { ctx.Handle(404, "repo.Single(GetReposFiles)", err) return @@ -200,18 +193,7 @@ func Single(ctx *middleware.Context, params martini.Params) { } } - // Get latest commit according username and repo name. - commit, err := models.GetCommit(userName, repoName, - branchName, commitId) - if err != nil { - log.Error("repo.Single(GetCommit): %v", err) - ctx.Handle(404, "repo.Single(GetCommit)", err) - return - } - ctx.Data["LastCommit"] = commit - - ctx.Data["CommitId"] = commitId - + ctx.Data["LastCommit"] = ctx.Repo.Commit ctx.Data["Paths"] = Paths ctx.Data["Treenames"] = treenames ctx.Data["BranchLink"] = branchLink @@ -219,11 +201,6 @@ func Single(ctx *middleware.Context, params martini.Params) { } func SingleDownload(ctx *middleware.Context, params martini.Params) { - if !ctx.Repo.IsValid { - ctx.Handle(404, "repo.SingleDownload", nil) - return - } - // Get tree path treename := params["_1"] @@ -263,10 +240,6 @@ func SingleDownload(ctx *middleware.Context, params martini.Params) { } func Http(ctx *middleware.Context, params martini.Params) { - /*if !ctx.Repo.IsValid { - return - }*/ - // TODO: access check username := params["username"] diff --git a/templates/issue/create.tmpl b/templates/issue/create.tmpl index f5cec0c0..01784cd2 100644 --- a/templates/issue/create.tmpl +++ b/templates/issue/create.tmpl @@ -4,7 +4,7 @@ {{template "repo/toolbar" .}}
    - + {{.CsrfTokenHtml}}
    @@ -40,4 +40,4 @@
    -{{template "base/footer" .}} \ No newline at end of file +{{template "base/footer" .}} diff --git a/templates/issue/list.tmpl b/templates/issue/list.tmpl index 7622a4c1..de25b0e3 100644 --- a/templates/issue/list.tmpl +++ b/templates/issue/list.tmpl @@ -6,24 +6,24 @@
    -{{template "base/footer" .}} \ No newline at end of file +{{template "base/footer" .}} diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index 91e5250c..df8b6607 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -64,7 +64,7 @@
    {{if .SignedUser}}
    -
    + {{.CsrfTokenHtml}}
    @@ -102,4 +102,4 @@
    -{{template "base/footer" .}} \ No newline at end of file +{{template "base/footer" .}} diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index e58f2d66..5c95ddef 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -1,7 +1,6 @@ {{template "base/head" .}} {{template "base/navbar" .}} {{template "repo/nav" .}} -{{template "repo/toolbar" .}}
    @@ -11,7 +10,7 @@
    - commit {{.ShortSha}} + commit {{ShortSha .CommitId}}

    diff --git a/templates/repo/single.tmpl b/templates/repo/single.tmpl index 4c940676..abaa4e89 100644 --- a/templates/repo/single.tmpl +++ b/templates/repo/single.tmpl @@ -11,11 +11,11 @@ {{ $n := len .Treenames}} {{if not .IsFile}}{{end}}

    diff --git a/templates/repo/toolbar.tmpl b/templates/repo/toolbar.tmpl index 75f1efdc..3c7c8a50 100644 --- a/templates/repo/toolbar.tmpl +++ b/templates/repo/toolbar.tmpl @@ -3,24 +3,24 @@
    -{{template "base/footer" .}} \ No newline at end of file +{{template "base/footer" .}} -- cgit v1.2.3 From a6e12aaef6344fff43745baa755c6afa11935550 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 30 Mar 2014 10:47:08 -0400 Subject: Fixing bug --- models/models.go | 25 ++++++++++++++++++++++++- modules/auth/user.go | 4 ++++ routers/install.go | 20 +++++++++++++++----- 3 files changed, 43 insertions(+), 6 deletions(-) (limited to 'models') diff --git a/models/models.go b/models/models.go index 825730c5..06533e45 100644 --- a/models/models.go +++ b/models/models.go @@ -17,7 +17,8 @@ import ( ) var ( - orm *xorm.Engine + orm *xorm.Engine + HasEngine bool DbCfg struct { Type, Host, Name, User, Pwd, Path, SslMode string @@ -34,6 +35,28 @@ func LoadModelsConfig() { DbCfg.Path = base.Cfg.MustValue("database", "PATH", "data/gogs.db") } +func NewTestEngine(x *xorm.Engine) (err error) { + switch DbCfg.Type { + case "mysql": + x, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", + DbCfg.User, DbCfg.Pwd, DbCfg.Host, DbCfg.Name)) + case "postgres": + x, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s", + DbCfg.User, DbCfg.Pwd, DbCfg.Name, DbCfg.SslMode)) + case "sqlite3": + os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm) + x, err = xorm.NewEngine("sqlite3", DbCfg.Path) + default: + return fmt.Errorf("Unknown database type: %s\n", DbCfg.Type) + } + if err != nil { + return fmt.Errorf("models.init(fail to conntect database): %v\n", err) + } + + return x.Sync(new(User), new(PublicKey), new(Repository), new(Watch), + new(Action), new(Access), new(Issue), new(Comment)) +} + func SetEngine() (err error) { switch DbCfg.Type { case "mysql": diff --git a/modules/auth/user.go b/modules/auth/user.go index cb8db1b2..6242a11c 100644 --- a/modules/auth/user.go +++ b/modules/auth/user.go @@ -21,6 +21,10 @@ import ( // SignedInId returns the id of signed in user. func SignedInId(session session.SessionStore) int64 { + if !models.HasEngine { + return 0 + } + userId := session.Get("userId") if userId == nil { return 0 diff --git a/routers/install.go b/routers/install.go index 36bba3d4..20e42419 100644 --- a/routers/install.go +++ b/routers/install.go @@ -11,6 +11,7 @@ import ( "github.com/Unknwon/goconfig" "github.com/codegangsta/martini" + // "github.com/lunny/xorm" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" @@ -38,9 +39,14 @@ func GlobalInit() { models.LoadModelsConfig() models.LoadRepoConfig() models.NewRepoContext() - if err := models.NewEngine(); err != nil && base.InstallLock { - log.Error("%v", err) - os.Exit(2) + + if base.InstallLock { + if err := models.NewEngine(); err != nil { + log.Error("%v", err) + os.Exit(2) + } + + models.HasEngine = true } base.NewServices() checkRunMode() @@ -107,7 +113,11 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { models.DbCfg.SslMode = form.SslMode models.DbCfg.Path = form.DatabasePath - if err := models.NewEngine(); err != nil { + // ctx.RenderWithErr("Database setting is not correct: ", "install", &form) + // return + log.Trace("00000000000000000000000000000000000000000000") + var x *xorm.Engine + if err := models.NewTestEngine(x); err != nil { if strings.Contains(err.Error(), `unknown driver "sqlite3"`) { ctx.RenderWithErr("Your release version does not support SQLite3, please download the official binary version "+ "from https://github.com/gogits/gogs/wiki/Install-from-binary, NOT the gobuild version.", "install", &form) @@ -158,7 +168,7 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { base.Cfg.SetValue("security", "INSTALL_LOCK", "true") - if err := goconfig.SaveConfigFile(base.Cfg, "custom/conf/app.ini"); err != nil { + if err := goconfig.SaveConfigFile(base.Cfg, "custom/conf/app1.ini"); err != nil { ctx.RenderWithErr("Fail to save configuration: "+err.Error(), "install", &form) return } -- cgit v1.2.3 From 9f91dee53fc602a939abf1219ec6ddb128c2067c Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 30 Mar 2014 11:09:59 -0400 Subject: Bug fix #45 --- models/models.go | 6 +++--- modules/base/conf.go | 4 ++-- routers/install.go | 28 +++++++++++++--------------- 3 files changed, 18 insertions(+), 20 deletions(-) (limited to 'models') diff --git a/models/models.go b/models/models.go index 06533e45..be176b5d 100644 --- a/models/models.go +++ b/models/models.go @@ -43,9 +43,9 @@ func NewTestEngine(x *xorm.Engine) (err error) { case "postgres": x, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s", DbCfg.User, DbCfg.Pwd, DbCfg.Name, DbCfg.SslMode)) - case "sqlite3": - os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm) - x, err = xorm.NewEngine("sqlite3", DbCfg.Path) + // case "sqlite3": + // os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm) + // x, err = xorm.NewEngine("sqlite3", DbCfg.Path) default: return fmt.Errorf("Unknown database type: %s\n", DbCfg.Type) } diff --git a/modules/base/conf.go b/modules/base/conf.go index f696d083..0233d003 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -253,7 +253,7 @@ func NewConfigContext() { cfgPath := filepath.Join(workDir, "conf/app.ini") Cfg, err = goconfig.LoadConfigFile(cfgPath) if err != nil { - fmt.Printf("Cannot load config file '%s'\n", cfgPath) + fmt.Printf("Cannot load config file(%s): %v\n", cfgPath, err) os.Exit(2) } Cfg.BlockMode = false @@ -261,7 +261,7 @@ func NewConfigContext() { cfgPath = filepath.Join(workDir, "custom/conf/app.ini") if com.IsFile(cfgPath) { if err = Cfg.AppendFiles(cfgPath); err != nil { - fmt.Printf("Cannot load config file '%s'\n", cfgPath) + fmt.Printf("Cannot load config file(%s): %v\n", cfgPath, err) os.Exit(2) } } diff --git a/routers/install.go b/routers/install.go index 20e42419..6f29badc 100644 --- a/routers/install.go +++ b/routers/install.go @@ -11,7 +11,7 @@ import ( "github.com/Unknwon/goconfig" "github.com/codegangsta/martini" - // "github.com/lunny/xorm" + "github.com/lunny/xorm" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" @@ -113,12 +113,10 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { models.DbCfg.SslMode = form.SslMode models.DbCfg.Path = form.DatabasePath - // ctx.RenderWithErr("Database setting is not correct: ", "install", &form) - // return - log.Trace("00000000000000000000000000000000000000000000") + // Set test engine. var x *xorm.Engine if err := models.NewTestEngine(x); err != nil { - if strings.Contains(err.Error(), `unknown driver "sqlite3"`) { + if strings.Contains(err.Error(), `Unknown database type: sqlite3`) { ctx.RenderWithErr("Your release version does not support SQLite3, please download the official binary version "+ "from https://github.com/gogits/gogs/wiki/Install-from-binary, NOT the gobuild version.", "install", &form) } else { @@ -133,15 +131,6 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { return } - // Create admin account. - if _, err := models.RegisterUser(&models.User{Name: form.AdminName, Email: form.AdminEmail, Passwd: form.AdminPasswd, - IsAdmin: true, IsActive: true}); err != nil { - if err != models.ErrUserAlreadyExist { - ctx.RenderWithErr("Admin account setting is invalid: "+err.Error(), "install", &form) - return - } - } - // Save settings. base.Cfg.SetValue("database", "DB_TYPE", models.DbCfg.Type) base.Cfg.SetValue("database", "HOST", models.DbCfg.Host) @@ -168,13 +157,22 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { base.Cfg.SetValue("security", "INSTALL_LOCK", "true") - if err := goconfig.SaveConfigFile(base.Cfg, "custom/conf/app1.ini"); err != nil { + if err := goconfig.SaveConfigFile(base.Cfg, "custom/conf/app.ini"); err != nil { ctx.RenderWithErr("Fail to save configuration: "+err.Error(), "install", &form) return } GlobalInit() + // Create admin account. + if _, err := models.RegisterUser(&models.User{Name: form.AdminName, Email: form.AdminEmail, Passwd: form.AdminPasswd, + IsAdmin: true, IsActive: true}); err != nil { + if err != models.ErrUserAlreadyExist { + ctx.RenderWithErr("Admin account setting is invalid: "+err.Error(), "install", &form) + return + } + } + log.Info("First-time run install finished!") ctx.Redirect("/user/login") } -- cgit v1.2.3 From 2a0066420a9395e5fa5afcd9be4d094a48eee3fa Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 30 Mar 2014 16:01:50 -0400 Subject: Fix bug work with sqlite3 --- models/access.go | 2 ++ models/models.go | 6 ++++++ models/repo.go | 2 +- models/user.go | 1 + modules/base/conf.go | 6 +++--- routers/install.go | 1 + serve.go | 19 +++++++++++-------- update.go | 6 ++++++ 8 files changed, 31 insertions(+), 12 deletions(-) (limited to 'models') diff --git a/models/access.go b/models/access.go index 84cad17a..42fccae0 100644 --- a/models/access.go +++ b/models/access.go @@ -26,6 +26,8 @@ type Access struct { // AddAccess adds new access record. func AddAccess(access *Access) error { + access.UserName = strings.ToLower(access.UserName) + access.RepoName = strings.ToLower(access.RepoName) _, err := orm.Insert(access) return err } diff --git a/models/models.go b/models/models.go index be176b5d..a626b98f 100644 --- a/models/models.go +++ b/models/models.go @@ -12,6 +12,7 @@ import ( _ "github.com/go-sql-driver/mysql" _ "github.com/lib/pq" "github.com/lunny/xorm" + // _ "github.com/mattn/go-sqlite3" "github.com/gogits/gogs/modules/base" ) @@ -23,10 +24,15 @@ var ( DbCfg struct { Type, Host, Name, User, Pwd, Path, SslMode string } + + UseSQLite3 bool ) func LoadModelsConfig() { DbCfg.Type = base.Cfg.MustValue("database", "DB_TYPE") + if DbCfg.Type == "sqlite3" { + UseSQLite3 = true + } DbCfg.Host = base.Cfg.MustValue("database", "HOST") DbCfg.Name = base.Cfg.MustValue("database", "NAME") DbCfg.User = base.Cfg.MustValue("database", "USER") diff --git a/models/repo.go b/models/repo.go index 5ca98dec..0c808f18 100644 --- a/models/repo.go +++ b/models/repo.go @@ -157,7 +157,7 @@ func CreateRepository(user *User, repoName, desc, repoLang, license string, priv } access := Access{ - UserName: user.Name, + UserName: user.LowerName, RepoName: strings.ToLower(path.Join(user.Name, repo.Name)), Mode: AU_WRITABLE, } diff --git a/models/user.go b/models/user.go index a392fa76..4908552f 100644 --- a/models/user.go +++ b/models/user.go @@ -39,6 +39,7 @@ var ( ErrUserNotExist = errors.New("User does not exist") ErrEmailAlreadyUsed = errors.New("E-mail already used") ErrUserNameIllegal = errors.New("User name contains illegal characters") + ErrKeyNotExist = errors.New("Public key does not exist") ) // User represents the object of individual and member of organization. diff --git a/modules/base/conf.go b/modules/base/conf.go index 0233d003..3ebc4ede 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -212,9 +212,9 @@ func newMailService() { if Cfg.MustBool("mailer", "ENABLED") { MailService = &Mailer{ Name: Cfg.MustValue("mailer", "NAME", AppName), - Host: Cfg.MustValue("mailer", "HOST", "127.0.0.1:25"), - User: Cfg.MustValue("mailer", "USER", "example@example.com"), - Passwd: Cfg.MustValue("mailer", "PASSWD", "******"), + Host: Cfg.MustValue("mailer", "HOST"), + User: Cfg.MustValue("mailer", "USER"), + Passwd: Cfg.MustValue("mailer", "PASSWD"), } log.Info("Mail Service Enabled") } diff --git a/routers/install.go b/routers/install.go index 2c993c55..e30c3cfd 100644 --- a/routers/install.go +++ b/routers/install.go @@ -185,6 +185,7 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { ctx.RenderWithErr("Admin account setting is invalid: "+err.Error(), "install", &form) return } + log.Info("Admin account already exist") } log.Info("First-time run install finished!") diff --git a/serve.go b/serve.go index dcbddfe4..96cd7e73 100644 --- a/serve.go +++ b/serve.go @@ -74,29 +74,33 @@ func In(b string, sl map[string]int) bool { func runServ(k *cli.Context) { execDir, _ := base.ExecDir() newLogger(execDir) - log.Trace("new serv request " + log.Mode + ":" + log.Config) base.NewConfigContext() models.LoadModelsConfig() + + if models.UseSQLite3 { + os.Chdir(execDir) + } + models.SetEngine() keys := strings.Split(os.Args[2], "-") if len(keys) != 2 { - fmt.Println("auth file format error") + println("auth file format error") log.Error("auth file format error") return } keyId, err := strconv.ParseInt(keys[1], 10, 64) if err != nil { - fmt.Println("auth file format error") + println("auth file format error") log.Error("auth file format error", err) return } user, err := models.GetUserByKeyId(keyId) if err != nil { - fmt.Println("You have no right to access") - log.Error("SSH visit error", err) + println("You have no right to access") + log.Error("SSH visit error: %v", err) return } @@ -133,13 +137,12 @@ func runServ(k *cli.Context) { // access check switch { case isWrite: - has, err := models.HasAccess(user.Name, strings.ToLower(path.Join(repoUserName, repoName)), models.AU_WRITABLE) + has, err := models.HasAccess(user.LowerName, path.Join(repoUserName, repoName), models.AU_WRITABLE) if err != nil { println("Inernel error:", err) log.Error(err.Error()) return - } - if !has { + } else if !has { println("You have no right to write this repository") log.Error("User %s has no right to write repository %s", user.Name, repoPath) return diff --git a/update.go b/update.go index 246c5d8f..e36dc223 100644 --- a/update.go +++ b/update.go @@ -32,6 +32,12 @@ gogs serv provide access auth for repositories`, func runUpdate(c *cli.Context) { base.NewConfigContext() models.LoadModelsConfig() + + if models.UseSQLite3 { + execDir, _ := base.ExecDir() + os.Chdir(execDir) + } + models.SetEngine() w, _ := os.Create("update.log") -- cgit v1.2.3