Show branches in repo viewer
This commit is contained in:
parent
7015c3d491
commit
685631627e
5 changed files with 43 additions and 17 deletions
|
@ -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.
|
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
|
## Purpose
|
||||||
|
|
||||||
|
|
3
bee.json
3
bee.json
|
@ -12,7 +12,8 @@
|
||||||
"models": "",
|
"models": "",
|
||||||
"others": [
|
"others": [
|
||||||
"modules",
|
"modules",
|
||||||
"$GOPATH/src/github.com/gogits/binding"
|
"$GOPATH/src/github.com/gogits/binding",
|
||||||
|
"$GOPATH/src/github.com/gogits/git"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"cmd_args": [
|
"cmd_args": [
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
git "github.com/gogits/git"
|
"github.com/gogits/git"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RepoFile struct {
|
type RepoFile struct {
|
||||||
|
@ -19,10 +19,26 @@ type RepoFile struct {
|
||||||
Size int64
|
Size int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) {
|
func GetBranches(userName, reposName string) ([]string, error) {
|
||||||
f := RepoPath(userName, reposName)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,13 @@ func Single(ctx *middleware.Context, params martini.Params) {
|
||||||
ctx.Data["Reponame"] = params["reponame"]
|
ctx.Data["Reponame"] = params["reponame"]
|
||||||
ctx.Data["Branchname"] = params["branchname"]
|
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
|
var treenames []string
|
||||||
Paths := make([]string, 0)
|
Paths := make([]string, 0)
|
||||||
|
|
||||||
|
|
|
@ -5,21 +5,23 @@
|
||||||
<div id="gogs-body" class="container">
|
<div id="gogs-body" class="container">
|
||||||
<div id="gogs-source">
|
<div id="gogs-source">
|
||||||
<div class="source-toolbar">
|
<div class="source-toolbar">
|
||||||
<button class="btn btn-default pull-right"><i class="fa fa-plus-square"></i>Add File</button>
|
{{ $username := .Username}}
|
||||||
<div class="dropdown branch-switch">
|
|
||||||
<a href="#" class="btn btn-success dropdown-toggle" data-toggle="dropdown"><i class="fa fa-chain"></i>master
|
|
||||||
<b class="caret"></b></a>
|
|
||||||
<ul class="dropdown-menu">
|
|
||||||
<li><a class="current" href="/{{.RepositoryLink}}/tree/master">master</a></li>
|
|
||||||
<li><a href="/{{.RepositoryLink}}/tree/develop">develop</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
{{$paths := .Paths}}
|
|
||||||
{{ $username := .Username}}
|
|
||||||
{{ $reponame := .Reponame}}
|
{{ $reponame := .Reponame}}
|
||||||
{{ $branchname := .Branchname}}
|
{{ $branchname := .Branchname}}
|
||||||
{{ $treenames := .Treenames}}
|
{{ $treenames := .Treenames}}
|
||||||
|
{{ $repoLink := .RepositoryLink}}
|
||||||
{{ $n := len $treenames}}
|
{{ $n := len $treenames}}
|
||||||
|
<button class="btn btn-default pull-right"><i class="fa fa-plus-square"></i>Add File</button>
|
||||||
|
<div class="dropdown branch-switch">
|
||||||
|
<a href="#" class="btn btn-success dropdown-toggle" data-toggle="dropdown"><i class="fa fa-chain"></i>{{$branchname}}
|
||||||
|
<b class="caret"></b></a>
|
||||||
|
<ul class="dropdown-menu">
|
||||||
|
{{range .Branches}}
|
||||||
|
<li><a {{if eq . $branchname}}class="current" {{end}}href="/{{$repoLink}}/tree/{{.}}">{{.}}</a></li>
|
||||||
|
{{end}}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{{$paths := .Paths}}
|
||||||
{{ $l := Subtract $n 1}}
|
{{ $l := Subtract $n 1}}
|
||||||
<ol class="breadcrumb">
|
<ol class="breadcrumb">
|
||||||
<li class="root dir"><a href="/{{$username}}/{{$reponame}}/tree/{{$branchname}}">{{.Repository.Name}}</a></li>
|
<li class="root dir"><a href="/{{$username}}/{{$reponame}}/tree/{{$branchname}}">{{.Repository.Name}}</a></li>
|
||||||
|
|
Loading…
Reference in a new issue