From b87f220fe3e0bd8f77c31ed1677f2df337c6ce8d Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Tue, 25 Jun 2024 20:50:53 +0200 Subject: update worktree after fetching updates --- internal/vcs/repository.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'internal/vcs') diff --git a/internal/vcs/repository.go b/internal/vcs/repository.go index cc9bdaa..56d439d 100644 --- a/internal/vcs/repository.go +++ b/internal/vcs/repository.go @@ -3,6 +3,7 @@ package vcs import ( "os" "website/internal/config" + "website/internal/log" "github.com/go-git/go-git/v5" gitc "github.com/go-git/go-git/v5/config" @@ -39,6 +40,7 @@ func CloneOrUpdate(cfg *Config) (*Repository, error) { if err != nil { return nil, err } + return repo, nil } @@ -48,6 +50,7 @@ func CloneOrUpdate(cfg *Config) (*Repository, error) { } func (r *Repository) Update(cfg *Config) (bool, error) { + log.Debug("updating repository") err := r.repo.Fetch(&git.FetchOptions{ RefSpecs: []gitc.RefSpec{ gitc.RefSpec( @@ -57,9 +60,21 @@ func (r *Repository) Update(cfg *Config) (bool, error) { }) if err != nil { if errors.Is(err, git.NoErrAlreadyUpToDate) { + log.Debug("no changes to pull") return false, nil } + + return false, err + } + + head, err := r.repo.Head() + if err != nil { return false, err } + log.Debug("applying changes", "head", head.Name()) + err = r.repo.Merge(*head, git.MergeOptions{ + Strategy: git.FastForwardMerge, + }) + return true, nil } -- cgit 1.4.1