diff --git a/models/repo.go b/models/repo.go index 6a764e6c318..1961b31e949 100644 --- a/models/repo.go +++ b/models/repo.go @@ -262,6 +262,17 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep return err } + // hook/post-update + pu2, err := os.OpenFile(filepath.Join(repoPath, "hooks", "post-receive"), os.O_CREATE|os.O_WRONLY, 0777) + if err != nil { + return err + } + defer pu2.Close() + // TODO: Windows .bat + if _, err = pu2.WriteString("#!/usr/bin/env bash\ngit update-server-info\n"); err != nil { + return err + } + // Initialize repository according to user's choice. fileName := map[string]string{} if initReadme { diff --git a/routers/repo/single.go b/routers/repo/single.go index eab49be919d..37c0fabd797 100644 --- a/routers/repo/single.go +++ b/routers/repo/single.go @@ -11,6 +11,7 @@ import ( "github.com/codegangsta/martini" "github.com/gogits/git" + "github.com/gogits/webdav" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" @@ -192,6 +193,29 @@ func Single(ctx *middleware.Context, params martini.Params) { ctx.HTML(200, "repo/single") } +func Http(ctx *middleware.Context, params martini.Params) { + /*if !ctx.Repo.IsValid { + return + }*/ + + // TODO: access check + + username := params["username"] + reponame := params["reponame"] + if strings.HasSuffix(reponame, ".git") { + reponame = reponame[:len(reponame)-4] + } + + prefix := path.Join("/", username, params["reponame"]) + server := &webdav.Server{ + Fs: webdav.Dir(models.RepoPath(username, reponame)), + TrimPrefix: prefix, + Listings: true, + } + + server.ServeHTTP(ctx.ResponseWriter, ctx.Req) +} + func Setting(ctx *middleware.Context, params martini.Params) { if !ctx.Repo.IsOwner { ctx.Error(404) diff --git a/web.go b/web.go index 54aaab573be..bb316a67246 100644 --- a/web.go +++ b/web.go @@ -139,6 +139,8 @@ func runWeb(*cli.Context) { m.Get("/:username/:reponame", ignSignIn, middleware.RepoAssignment(true), repo.Single) + m.Any("/:username/:reponame/**", ignSignIn, repo.Http) + if martini.Env == martini.Dev { m.Get("/template/**", dev.TemplatePreview) }