From 973fa31b6743a3ea84c86ab7671349cc70a69142 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sat, 29 Jun 2024 21:27:35 +0200 Subject: enable filtered debug logging via DEBUG="component.*" --- internal/vcs/repository.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'internal/vcs') diff --git a/internal/vcs/repository.go b/internal/vcs/repository.go index 1dbf783..017b3d8 100644 --- a/internal/vcs/repository.go +++ b/internal/vcs/repository.go @@ -18,9 +18,10 @@ type Config struct { type Repository struct { repo *git.Repository + log *log.Logger } -func CloneOrUpdate(cfg *Config) (*Repository, error) { +func CloneOrUpdate(cfg *Config, log *log.Logger) (*Repository, error) { gr, err := git.PlainClone(cfg.LocalPath, false, &git.CloneOptions{ URL: cfg.RemoteURL.String(), Progress: os.Stdout, @@ -35,6 +36,7 @@ func CloneOrUpdate(cfg *Config) (*Repository, error) { } repo := &Repository{ repo: gr, + log: log, } _, err := repo.Update() if err != nil { @@ -46,18 +48,19 @@ func CloneOrUpdate(cfg *Config) (*Repository, error) { return &Repository{ repo: gr, + log: log, }, nil } func (r *Repository) Update() (bool, error) { - log.Info("updating repository") + r.log.Info("updating repository") head, err := r.repo.Head() if err != nil { return false, err } - log.Info("updating from", "rev", head.Hash().String()) + r.log.Info("updating from", "rev", head.Hash().String()) wt, err := r.repo.Worktree() if err != nil { return false, err @@ -68,7 +71,7 @@ func (r *Repository) Update() (bool, error) { }) if err != nil { if errors.Is(err, git.NoErrAlreadyUpToDate) { - log.Info("already up-to-date") + r.log.Info("already up-to-date") return true, nil } @@ -80,7 +83,7 @@ func (r *Repository) Update() (bool, error) { if err != nil { return false, err } - log.Info("updated to", "rev", head.Hash().String()) + r.log.Info("updated to", "rev", head.Hash().String()) return true, r.Clean(wt) } -- cgit 1.4.1