commit
message
Allowing for static hosted repos via 'git update-server-info'
author
Ben Vogt <[email protected]>
date
2023-04-05 17:33:18
stats
4 file(s) changed,
25 insertions(+),
15 deletions(-)
files
README.md
config.go
gshr.toml
main.go
1diff --git a/README.md b/README.md
2index 4a737c8..1849107 100644
3--- a/README.md
4+++ b/README.md
5@@ -32,8 +32,6 @@ See more examples in [tree/master/examples](tree/master/examples).
6
7 ```
8 Usage of gshr:
9- -clone string
10- Dir to clone into. Default is /tmp/${rand}
11 -config string
12 Config file.
13 -output string
14diff --git a/config.go b/config.go
15index 9804115..2156585 100644
16--- a/config.go
17+++ b/config.go
18@@ -24,7 +24,7 @@ type Repo struct {
19 // / CloneDir gets the directory that this repo was cloned into using the output directory
20 // / from the program arguments, and this repo's name.
21 func (r *Repo) CloneDir() string {
22- return path.Join(args.OutputDir, "git", r.Name)
23+ return path.Join(args.OutputDir, r.Name, "git")
24 }
25
26 func (r *Repo) FindFileInRoot(oneOfThese map[string]bool) string {
27diff --git a/gshr.toml b/gshr.toml
28index e0cdcc7..fe598f8 100644
29--- a/gshr.toml
30+++ b/gshr.toml
31@@ -6,15 +6,4 @@ name = "gshr"
32 description = "git static host repo -- generates static html for repos"
33 url = "/Users/bvogt/dev/src/ben/gshr"
34 published_git_url = "[email protected]:vogtb/gshr.git"
35-
36-[[repos]]
37-name = "www"
38-description = "static site for www.vogt.world"
39-url = "/Users/bvogt/dev/src/ben/www"
40-published_git_url = "[email protected]:vogtb/www.git"
41-
42-[[repos]]
43-name = "f7"
44-description = "f7 is a spreadsheet formula execution library"
45-url = "/Users/bvogt/dev/src/ben/f7"
46-published_git_url = "[email protected]:vogtb/f7.git"
47+host_git = true
48diff --git a/main.go b/main.go
49index f776345..58493a4 100644
50--- a/main.go
51+++ b/main.go
52@@ -8,6 +8,7 @@ import (
53 "fmt"
54 "log"
55 "os"
56+ "os/exec"
57 "path"
58
59 "github.com/alecthomas/chroma/formatters/html"
60@@ -45,6 +46,9 @@ func main() {
61 }
62 RenderIndexPage(allRepoData)
63 RenderAssets()
64+ for _, repo := range config.Repos {
65+ HostRepo(repo)
66+ }
67 }
68
69 func Init() {
70@@ -95,6 +99,23 @@ func RenderAssets() {
71 checkErr(os.WriteFile(path.Join(args.OutputDir, "favicon.ico"), favicon, 0666))
72 }
73
74+func HostRepo(data Repo) {
75+ if data.HostGit {
76+ debug("hosting of '%v' is ON", data.Name)
77+ old := path.Join(data.CloneDir(), ".git")
78+ new := path.Join(args.OutputDir, fmt.Sprintf("%v.git", data.Name))
79+ debug("renaming '%v', new %v", data.Name, new)
80+ checkErr(os.Rename(old, new))
81+ debug("running 'git update-server-info' in %v", new)
82+ cmd := exec.Command("git", "update-server-info")
83+ cmd.Dir = new
84+ checkErr(cmd.Run())
85+ debug("hosting '%v' at %v", data.Name, new)
86+ } else {
87+ debug("hosting of '%v' is OFF", data.Name)
88+ }
89+}
90+
91 type LogWriter struct{}
92
93 func (writer LogWriter) Write(bytes []byte) (int, error) {