diff --git a/models/publickey.go b/models/publickey.go index 021d690fb..092436d55 100644 --- a/models/publickey.go +++ b/models/publickey.go @@ -23,7 +23,7 @@ import ( const ( // "### autogenerated by gitgos, DO NOT EDIT\n" - TPL_PUBLICK_KEY = `command="%s serv key-%d",no-port-forwarding, no-X11-forwarding,no-agent-forwarding,no-pty %s` + TPL_PUBLICK_KEY = `command="%s serv key-%d",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty %s` ) var ( diff --git a/models/repo.go b/models/repo.go index c377747a6..6e3754acf 100644 --- a/models/repo.go +++ b/models/repo.go @@ -223,6 +223,17 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep return err } + // hook/post-update + pu, err := os.OpenFile(filepath.Join(repoPath, "hooks", "post-update"), os.O_CREATE|os.O_WRONLY, 0777) + if err != nil { + return err + } + defer pu.Close() + // TODO: Windows .bat + if _, err = pu.WriteString(fmt.Sprintf("#!/usr/bin/env bash\n%s update\n", appPath)); err != nil { + return err + } + // Initialize repository according to user's choice. fileName := map[string]string{} if initReadme { @@ -275,11 +286,14 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep } } + if len(fileName) == 0 { + return nil + } + // Apply changes and commit. if err := initRepoCommit(tmpDir, user.NewGitSig()); err != nil { return err } - return nil } diff --git a/routers/repo/single.go b/routers/repo/single.go index e403d70e4..1b5da9d30 100644 --- a/routers/repo/single.go +++ b/routers/repo/single.go @@ -13,6 +13,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" ) @@ -21,15 +22,18 @@ func Branches(ctx *middleware.Context, params martini.Params) { return } - ctx.Data["Username"] = params["username"] - ctx.Data["Reponame"] = params["reponame"] - brs, err := models.GetBranches(params["username"], params["reponame"]) if err != nil { ctx.Handle(200, "repo.Branches", err) return + } else if len(brs) == 0 { + ctx.Render.Error(404) + return } + ctx.Data["Username"] = params["username"] + ctx.Data["Reponame"] = params["reponame"] + ctx.Data["Branchname"] = brs[0] ctx.Data["Branches"] = brs ctx.Data["IsRepoToolbarBranches"] = true @@ -49,25 +53,32 @@ func Single(ctx *middleware.Context, params martini.Params) { // Get tree path treename := params["_1"] + // Branches. + brs, err := models.GetBranches(params["username"], params["reponame"]) + if err != nil { + log.Error("repo.Single(GetBranches): %v", err) + ctx.Render.Error(404) + return + } else if len(brs) == 0 { + ctx.Data["IsBareRepo"] = true + ctx.Render.HTML(200, "repo/single", ctx.Data) + return + } + + ctx.Data["Branches"] = brs + // Directory and file list. files, err := models.GetReposFiles(params["username"], params["reponame"], params["branchname"], treename) if err != nil { - ctx.Handle(200, "repo.Single(GetReposFiles)", err) + log.Error("repo.Single(GetReposFiles): %v", err) + ctx.Render.Error(404) return } ctx.Data["Username"] = params["username"] ctx.Data["Reponame"] = params["reponame"] ctx.Data["Branchname"] = params["branchname"] - // Branches. - brs, err := models.GetBranches(params["username"], params["reponame"]) - if err != nil { - ctx.Handle(200, "repo.Single(GetBranches)", err) - return - } - ctx.Data["Branches"] = brs - var treenames []string Paths := make([]string, 0) @@ -81,7 +92,8 @@ func Single(ctx *middleware.Context, params martini.Params) { // Get latest commit according username and repo name commit, err := models.GetLastestCommit(params["username"], params["reponame"]) if err != nil { - ctx.Handle(200, "repo.Single(GetLastestCommit)", err) + log.Error("repo.Single(GetLastestCommit): %v", err) + ctx.Render.Error(404) return } ctx.Data["LatestCommit"] = commit @@ -126,6 +138,18 @@ func Setting(ctx *middleware.Context, params martini.Params) { return } + // Branches. + brs, err := models.GetBranches(params["username"], params["reponame"]) + if err != nil { + log.Error("repo.Setting(GetBranches): %v", err) + ctx.Render.Error(404) + return + } else if len(brs) == 0 { + ctx.Data["IsBareRepo"] = true + ctx.Render.HTML(200, "repo/setting", ctx.Data) + return + } + var title string if t, ok := ctx.Data["Title"].(string); ok { title = t @@ -137,6 +161,15 @@ func Setting(ctx *middleware.Context, params martini.Params) { } func Commits(ctx *middleware.Context, params martini.Params) { + brs, err := models.GetBranches(params["username"], params["reponame"]) + if err != nil { + ctx.Handle(200, "repo.Commits", err) + return + } else if len(brs) == 0 { + ctx.Render.Error(404) + return + } + ctx.Data["IsRepoToolbarCommits"] = true commits, err := models.GetCommits(params["username"], params["reponame"], params["branchname"]) diff --git a/serve.go b/serve.go index fcbde3e5f..ddc670235 100644 --- a/serve.go +++ b/serve.go @@ -149,8 +149,7 @@ func runServ(*cli.Context) { gitcmd.Stdin = os.Stdin gitcmd.Stderr = os.Stderr - err = gitcmd.Run() - if err != nil { + if err = gitcmd.Run(); err != nil { println("execute command error:", err.Error()) } } diff --git a/templates/repo/nav.tmpl b/templates/repo/nav.tmpl index b41b62d5d..1f74bc306 100644 --- a/templates/repo/nav.tmpl +++ b/templates/repo/nav.tmpl @@ -4,10 +4,11 @@

{{.Owner.Name}} / {{.Repository.Name}}

+ {{if not .IsBareRepo}}
-
@@ -36,6 +37,7 @@
+ {{end}} \ No newline at end of file diff --git a/templates/repo/single.tmpl b/templates/repo/single.tmpl index cbc82e51c..019ec8eaa 100644 --- a/templates/repo/single.tmpl +++ b/templates/repo/single.tmpl @@ -4,6 +4,9 @@ {{template "repo/toolbar" .}}
+ {{if .IsBareRepo}} + Need to fill in some guide. + {{else}}
{{ $username := .Username}} {{ $reponame := .Reponame}} @@ -36,6 +39,7 @@ {{end}}
+
{{.LatestCommit.Message}} @@ -95,6 +99,7 @@ {{end}}
{{end}} + {{end}}
{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/repo/toolbar.tmpl b/templates/repo/toolbar.tmpl index c6e5f5f3c..5cd9f526b 100644 --- a/templates/repo/toolbar.tmpl +++ b/templates/repo/toolbar.tmpl @@ -4,6 +4,7 @@