web frontend for git (tangled's grandpa)
7
fork

Configure Feed

Select the types of activity you want to include in your feed.

routes: refs view

+104
+32
git/git.go
··· 78 78 79 79 return file.Contents() 80 80 } 81 + 82 + func (g *GitRepo) Tags() ([]*object.Tag, error) { 83 + ti, err := g.r.TagObjects() 84 + if err != nil { 85 + return nil, fmt.Errorf("tag objects: %w", err) 86 + } 87 + 88 + tags := []*object.Tag{} 89 + 90 + _ = ti.ForEach(func(t *object.Tag) error { 91 + tags = append(tags, t) 92 + return nil 93 + }) 94 + 95 + return tags, nil 96 + } 97 + 98 + func (g *GitRepo) Branches() ([]*plumbing.Reference, error) { 99 + bi, err := g.r.Branches() 100 + if err != nil { 101 + return nil, fmt.Errorf("branchs: %w", err) 102 + } 103 + 104 + branches := []*plumbing.Reference{} 105 + 106 + _ = bi.ForEach(func(ref *plumbing.Reference) error { 107 + branches = append(branches, ref) 108 + return nil 109 + }) 110 + 111 + return branches, nil 112 + }
+1
routes/handler.go
··· 21 21 mux.HandleFunc("/:name/blob/:ref/...", d.FileContent, "GET") 22 22 mux.HandleFunc("/:name/log/:ref", d.Log, "GET") 23 23 mux.HandleFunc("/:name/commit/:ref", d.Diff, "GET") 24 + mux.HandleFunc("/:name/refs", d.Refs, "GET") 24 25 return mux 25 26 }
+39
routes/routes.go
··· 216 216 return 217 217 } 218 218 } 219 + 220 + func (d *deps) Refs(w http.ResponseWriter, r *http.Request) { 221 + name := flow.Param(r.Context(), "name") 222 + 223 + path := filepath.Join(d.c.Git.ScanPath, name) 224 + gr, err := git.Open(path, "") 225 + if err != nil { 226 + d.Write404(w) 227 + return 228 + } 229 + 230 + tags, err := gr.Tags() 231 + if err != nil { 232 + // Non-fatal, we *should* have at least one branch to show. 233 + log.Println(err) 234 + } 235 + 236 + branches, err := gr.Branches() 237 + if err != nil { 238 + log.Println(err) 239 + d.Write500(w) 240 + return 241 + } 242 + 243 + tpath := filepath.Join(d.c.Template.Dir, "*") 244 + t := template.Must(template.ParseGlob(tpath)) 245 + 246 + data := make(map[string]interface{}) 247 + 248 + data["meta"] = d.c.Meta 249 + data["name"] = name 250 + data["branches"] = branches 251 + data["tags"] = tags 252 + 253 + if err := t.ExecuteTemplate(w, "refs", data); err != nil { 254 + log.Println(err) 255 + return 256 + } 257 + }
+32
templates/refs.html
··· 1 + {{ define "refs" }} 2 + <html> 3 + {{ template "head" . }} 4 + 5 + <header> 6 + <h1>{{ .meta.Title }}</h1> 7 + <h2>{{ .meta.Description }}</h2> 8 + </header> 9 + <body> 10 + {{ template "nav" . }} 11 + <main> 12 + <h3>branches</h3> 13 + {{ $name := .name }} 14 + {{ range .branches }} 15 + <p> 16 + <strong>{{ .Name.Short }}</strong> 17 + <a href="/{{ $name }}/tree/{{ .Name.Short }}/">browse</a> 18 + <a href="/{{ $name }}/log/{{ .Name.Short }}">log</a> 19 + </p> 20 + {{ end }} 21 + {{ if .tags }} 22 + {{ range .tags }} 23 + <p>{{ .Name }}</p> 24 + {{ if .Message }} 25 + <p>{{ .Message }}</p> 26 + {{ end }} 27 + {{ end }} 28 + {{ end }} 29 + </main> 30 + </body> 31 + </html> 32 + {{ end }}