all repos — website @ b87f220fe3e0bd8f77c31ed1677f2df337c6ce8d

My website

update worktree after fetching updates
Alan Pearce alan@alanpearce.eu
Tue, 25 Jun 2024 20:50:53 +0200
commit

b87f220fe3e0bd8f77c31ed1677f2df337c6ce8d

parent

7550950f27e5904cfb23ca492feb402edafbcb9a

1 files changed, 15 insertions(+), 0 deletions(-)

jump to
M internal/vcs/repository.gointernal/vcs/repository.go
@@ -3,6 +3,7 @@ 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 @@ _, err := repo.Update(cfg) 		if err != nil {
 			return nil, err
 		}
+
 		return repo, nil
 	}
 
@@ -48,6 +50,7 @@ }, nil }
 
 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 @@ }, 	})
 	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
 }