From 685631627e5c4db881160bfc9b39dc45143989f6 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 16 Mar 2014 23:43:22 -0400 Subject: [PATCH 1/2] Show branches in repo viewer --- README.md | 2 +- bee.json | 3 ++- models/repo2.go | 24 ++++++++++++++++++++---- routers/repo/single.go | 7 +++++++ templates/repo/single.tmpl | 24 +++++++++++++----------- 5 files changed, 43 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index f4250a47a4..d0a0c2054c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Gogs(Go Git Service) is a GitHub-like clone in the Go Programming Language. Since we choose to use pure Go implmentation of Git manipulation, Gogs certainly supports **ALL platforms** that Go supports, including Linux, Max OS X, and Windows with **ZERO** dependency. -##### Current version: 0.0.8 Alpha +##### Current version: 0.0.9 Alpha ## Purpose diff --git a/bee.json b/bee.json index de211f7277..19efcbc205 100644 --- a/bee.json +++ b/bee.json @@ -12,7 +12,8 @@ "models": "", "others": [ "modules", - "$GOPATH/src/github.com/gogits/binding" + "$GOPATH/src/github.com/gogits/binding", + "$GOPATH/src/github.com/gogits/git" ] }, "cmd_args": [ diff --git a/models/repo2.go b/models/repo2.go index e3fdc2784b..a8dbc44db9 100644 --- a/models/repo2.go +++ b/models/repo2.go @@ -8,7 +8,7 @@ import ( "path" "time" - git "github.com/gogits/git" + "github.com/gogits/git" ) type RepoFile struct { @@ -19,10 +19,26 @@ type RepoFile struct { Size int64 } -func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) { - f := RepoPath(userName, reposName) +func GetBranches(userName, reposName string) ([]string, error) { + repo, err := git.OpenRepository(RepoPath(userName, reposName)) + if err != nil { + return nil, err + } - repo, err := git.OpenRepository(f) + refs, err := repo.AllReferences() + if err != nil { + return nil, err + } + + brs := make([]string, len(refs)) + for i, ref := range refs { + brs[i] = ref.Name + } + return brs, nil +} + +func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) { + repo, err := git.OpenRepository(RepoPath(userName, reposName)) if err != nil { return nil, err } diff --git a/routers/repo/single.go b/routers/repo/single.go index 6bf03ca2b8..fd4d529031 100644 --- a/routers/repo/single.go +++ b/routers/repo/single.go @@ -33,6 +33,13 @@ func Single(ctx *middleware.Context, params martini.Params) { ctx.Data["Reponame"] = params["reponame"] ctx.Data["Branchname"] = params["branchname"] + brs, err := models.GetBranches(params["username"], params["reponame"]) + if err != nil { + ctx.Handle(200, "repo.Single", err) + return + } + ctx.Data["Branches"] = brs + var treenames []string Paths := make([]string, 0) diff --git a/templates/repo/single.tmpl b/templates/repo/single.tmpl index b5207d0820..e1fb05bd03 100644 --- a/templates/repo/single.tmpl +++ b/templates/repo/single.tmpl @@ -5,21 +5,23 @@
- - - {{$paths := .Paths}} - {{ $username := .Username}} + {{ $username := .Username}} {{ $reponame := .Reponame}} {{ $branchname := .Branchname}} {{ $treenames := .Treenames}} + {{ $repoLink := .RepositoryLink}} {{ $n := len $treenames}} + + + {{$paths := .Paths}} {{ $l := Subtract $n 1}}
- Merge branch 'release/1.1.1' + {{.LatestCommit.Message}}
- slene authored 4 days ago + {{.LatestCommit.Author}} {{TimeSince .LatestCommit.Date}}