diff --git a/models/repo2.go b/models/repo2.go index 91c057808b..8356c52de4 100644 --- a/models/repo2.go +++ b/models/repo2.go @@ -191,3 +191,15 @@ func GetLastestCommit(userName, repoName string) (*Commit, error) { } return commit, nil } + +func GetCommits(userName, reposName, branchname string) ([]*git.Commit, error) { + repo, err := git.OpenRepository(RepoPath(userName, reposName)) + if err != nil { + return nil, err + } + r, err := repo.LookupReference(fmt.Sprintf("refs/heads/%s", branchname)) + if err != nil { + return nil, err + } + return r.AllCommits() +} diff --git a/routers/repo/single.go b/routers/repo/single.go index cf64cc6b52..eda71f2925 100644 --- a/routers/repo/single.go +++ b/routers/repo/single.go @@ -131,8 +131,15 @@ func Setting(ctx *middleware.Context, params martini.Params) { ctx.Render.HTML(200, "repo/setting", ctx.Data) } -func Commits(ctx *middleware.Context) { +func Commits(ctx *middleware.Context, params martini.Params) { ctx.Data["IsRepoToolbarCommits"] = true + commits, err := models.GetCommits(params["username"], + params["reponame"], params["branchname"]) + if err != nil { + ctx.Render.Error(404) + return + } + ctx.Data["Commits"] = commits ctx.Render.HTML(200, "repo/commits", ctx.Data) } diff --git a/templates/repo/commits.tmpl b/templates/repo/commits.tmpl index 7ebe68b6a0..9190a030a3 100644 --- a/templates/repo/commits.tmpl +++ b/templates/repo/commits.tmpl @@ -4,6 +4,11 @@ {{template "repo/toolbar" .}}