web frontend for git repositories, written in Go git.pocka.jp/legit.git
3

Configure Feed

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

Resolve paths from config file, not cwd

I was surprised during writing "demo/config.yaml".

Shota FUJI (Mar 24, 2025, 4:13 PM +0900) 31530491 b8430efe

+16 -15
-6
config.yaml
··· 1 1 repo: 2 2 # Directory containing git repositories to serve. 3 - # Relative path is resolved from *current working directory* not from 4 - # path to the config file. 5 3 scanPath: /var/www/git 6 4 7 5 # Which filename will be treated as README file? ··· 28 26 # Path to a directory containing HTML templates. 29 27 # Templates are written in Go's html/template syntax. 30 28 # <https://pkg.go.dev/html/template> 31 - # Relative path is resolved from *current working directory* not from 32 - # path to the config file. 33 29 templates: ./templates 34 30 35 31 # Path to a directory containing static assets. 36 32 # User can access files in this directory by accessing "/static/*". 37 - # Relative path is resolved from *current working directory* not from 38 - # path to the config file. 39 33 static: ./static 40 34 41 35 meta:
+13 -3
config/config.go
··· 43 43 return nil, fmt.Errorf("parsing config: %w", err) 44 44 } 45 45 46 - if c.Repo.ScanPath, err = filepath.Abs(c.Repo.ScanPath); err != nil { 46 + if c.Repo.ScanPath, err = resolvePath(c.Repo.ScanPath, f); err != nil { 47 47 return nil, err 48 48 } 49 - if c.Dirs.Templates, err = filepath.Abs(c.Dirs.Templates); err != nil { 49 + if c.Dirs.Templates, err = resolvePath(c.Dirs.Templates, f); err != nil { 50 50 return nil, err 51 51 } 52 - if c.Dirs.Static, err = filepath.Abs(c.Dirs.Static); err != nil { 52 + if c.Dirs.Static, err = resolvePath(c.Dirs.Static, f); err != nil { 53 53 return nil, err 54 54 } 55 55 56 56 return &c, nil 57 57 } 58 + 59 + func resolvePath(target string, configPath string) (string, error) { 60 + if filepath.IsAbs(target) { 61 + return target, nil 62 + } 63 + 64 + dir := filepath.Dir(configPath) 65 + 66 + return filepath.Abs(filepath.Join(dir, target)) 67 + }
+3 -6
demo/config.yaml
··· 14 14 # cd demo && git clone --bare https://your-git-repo 15 15 16 16 repo: 17 - # TODO: Change to relative path once path resolution is fixed 18 - scanPath: ./demo 17 + scanPath: . 19 18 readme: 20 19 - readme 21 20 - README ··· 30 29 - trunk 31 30 32 31 dirs: 33 - # TODO: Change to relative path once path resolution is fixed 34 - templates: ./templates 35 - # TODO: Change to relative path once path resolution is fixed 36 - static: ./static 32 + templates: ../templates 33 + static: ../static 37 34 38 35 meta: 39 36 title: legit Demo