all repos — homestead @ b8fdd74d857b45c0ad573ff700bfd0bfbec3099c

Code for my website

update source repository if worktree exists

Alan Pearce
commit

b8fdd74d857b45c0ad573ff700bfd0bfbec3099c

parent

bd77f727dca007014f42269b9dd48b92df28f657

1 file changed, 20 insertions(+), 12 deletions(-)

changed files
M internal/website/mux.gointernal/website/mux.go
@@ -32,6 +32,10 @@ Destination string `conf:"default:public"`
Redirect bool `conf:"default:true"` Development bool `conf:"default:false,flag:dev"` BaseURL config.URL `conf:"default:localhost"` + VCS struct { + Branch string `conf:"default:main"` + RemoteURL config.URL `conf:"default:https://git.alanpearce.eu/website"` + } } type Website struct {
@@ -96,6 +100,22 @@ }
templates.Setup() + repo, err, exists := vcs.CloneOrOpen(&vcs.Options{ + LocalPath: opts.Source, + RemoteURL: opts.VCS.RemoteURL, + Branch: opts.VCS.Branch, + }, log.Named("vcs")) + if err != nil { + return nil, errors.WithMessage(err, "could not open repository") + } + + if exists && !opts.Development { + _, err := repo.Update() + if err != nil { + return nil, errors.WithMessage(err, "could not update repository") + } + } + log.Debug("getting config from source", "source", opts.Source) cfg, err := config.GetConfig(opts.Source, log) if err != nil {
@@ -120,18 +140,6 @@ cfg.BaseURL = opts.BaseURL
} website.Domain = cfg.BaseURL.Hostname() - - repo, err := vcs.CloneOrOpen(&vcs.Options{ - LocalPath: opts.Source, - RemoteURL: cfg.VCS.RemoteURL, - Branch: cfg.VCS.Branch, - }, log.Named("vcs")) - if err != nil { - return nil, errors.WithMessage(err, "could not update repository") - } - - _ = repo - // config may have changed, reload err = rebuild(builderOptions, cfg, log) if err != nil {